ZQuest Classic Coverage Report


Directory: src/
File: src/zq/zq_class.cpp
Date: 2025-11-27 06:33:24
Exec Total Coverage
Lines: 3114 8813 35.3%
Functions: 84 313 26.8%
Branches: 2716 7799 34.8%

Line Branch Exec Source
1 #include <chrono>
2 #include <cstring>
3 #include <exception>
4 #include <string>
5 #include <stdexcept>
6 #include <map>
7
8 #include "base/general.h"
9 #include "base/pal_tables.h"
10 #include "base/version.h"
11 #include "base/zapp.h"
12 #include "base/zdefs.h"
13 #include "dialog/info.h"
14 #include "gui/jwin.h"
15 #include "metadata/metadata.h"
16
17 #include "base/qrs.h"
18 #include "base/dmap.h"
19 #include "base/packfile.h"
20 #include "base/cpool.h"
21 #include "base/autocombo.h"
22 #include "base/gui.h"
23 #include "base/msgstr.h"
24 #include "zc/zelda.h"
25 #include "zq/zq_class.h"
26 #include "zq/render.h"
27 #include "zq/render_map_view.h"
28 #include "zq/zq_misc.h"
29 #include "zq/zquest.h"
30 #include "base/qst.h"
31 #include "base/colors.h"
32 #include "tiles.h"
33 #include "base/zsys.h"
34 #include "sprite.h"
35 #include "items.h"
36 #include "zc/zc_sys.h"
37 #include "base/md5.h"
38 #include "hero_tiles.h"
39 #include "subscr.h"
40 #include "zq/zq_strings.h"
41 #include "zq/zq_subscr.h"
42 #include "zc/ffscript.h"
43 #include "base/util.h"
44 #include "zq/zq_files.h"
45 #include "dialog/alert.h"
46 #include "slopes.h"
47 #include "drawing.h"
48 #include "zinfo.h"
49 #include "zq/render_minimap.h"
50 #include "base/mapscr.h"
51 #include "iter.h"
52 #include <fmt/format.h>
53 #include <filesystem>
54
55 #ifdef __EMSCRIPTEN__
56 #include "base/emscripten_utils.h"
57 #endif
58
59 namespace fs = std::filesystem;
60
61 using namespace util;
62
63 extern uint8_t ViewLayer3BG, ViewLayer2BG;
64 extern int32_t LayerDitherBG, LayerDitherSz;
65 extern bool NoHighlightLayer0;
66
67 using std::string;
68 using std::pair;
69
70 #define COLOR_SOLID vc(4)
71 #define COLOR_SLOPE vc(13)
72 #define COLOR_LADDER vc(6)
73 //#define COLOR_EFFECT vc(10)
74
75 //const char zqsheader[30]="ZQuest Classic String Table\n\x01";
76 extern char msgbuf[MSG_NEW_SIZE*8];
77
78 extern string zScript;
79
80 12 zmap Map;
81 int32_t prv_mode=0;
82
83 bool save_warn=true;
84
85 int32_t COMBOPOS(int32_t x, int32_t y)
86 {
87 return (((y) & 0xF0) + ((x) >> 4));
88 }
89 int32_t COMBOPOS_B(int32_t x, int32_t y)
90 {
91 if(unsigned(x) >= 256 || unsigned(y) >= 176)
92 return -1;
93 return COMBOPOS(x,y);
94 }
95 int32_t COMBOX(int32_t pos)
96 {
97 return ((pos) % 16 * 16);
98 }
99 int32_t COMBOY(int32_t pos)
100 {
101 return ((pos) & 0xF0);
102 }
103
104 void reset_dmap(int32_t index)
105 {
106 bound(index,0,MAXDMAPS-1);
107 DMaps[index].clear();
108 DMaps[index].title = "";
109 sprintf(DMaps[index].intro, " ");
110 }
111
112 void reset_dmaps()
113 {
114 for(int32_t i=0; i<MAXDMAPS; i++)
115 reset_dmap(i);
116 }
117
118 void truncate_dmap_title(std::string& title)
119 {
120 title.resize(21, ' ');
121 }
122
123 mapscr* zmap::get_prvscr()
124 {
125 return &prvscr;
126 }
127
128
7/12
✓ Branch 0 taken 23 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 23 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 138 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 115 times.
✓ Branch 7 taken 23 times.
✓ Branch 8 taken 23 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 23 times.
✗ Branch 11 not taken.
138 zmap::zmap()
129 {
130 23 can_paste=false;
131 23 prv_cmbcycle=0;
132 23 prv_advance=0;
133 23 prv_freeze=0;
134 23 copyffc=-1;
135
136 23 memset(scrpos, 0, sizeof(scrpos));
137 23 memset(scrview, 0, sizeof(scrview));
138 23 screens=NULL;
139 23 prv_time=0;
140 23 prv_scr=0;
141 23 prv_map=0;
142 23 copyscr=0;
143 23 cursor={};
144 copymap=0;
145 layer_target_map = 0;
146 layer_target_scr = 0;
147 layer_target_multiple = 0;
148 }
149
150 11 void zmap::clear()
151 {
152
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 *this = zmap();
153 11 }
154 void zmap::force_refr_pointer()
155 {
156 if(unsigned(cursor.map) > map_count || (cursor.map*MAPSCRS > TheMaps.size()))
157 screens = nullptr;
158 else screens = &TheMaps[cursor.map*MAPSCRS];
159 }
160 bool zmap::CanUndo()
161 {
162 return input_undo_stack.size() > 0;
163 }
164 bool zmap::CanRedo()
165 {
166 return input_redo_stack.size() > 0;
167 }
168 bool zmap::CanPaste()
169 {
170 return can_paste;
171 }
172 int32_t zmap::CopyScr()
173 {
174 return (copymap<<8)+copyscr;
175 }
176 int32_t zmap::getCopyFFC()
177 {
178 return copyffc;
179 }
180 set_ffc_command::data_t zmap::getCopyFFCData()
181 {
182 return set_ffc_command::create_data(copymapscr.ffcs[copyffc]);
183 }
184 67 int32_t zmap::getMapCount()
185 {
186 67 return map_count;
187 }
188 int32_t zmap::getLayerTargetMap()
189 {
190 return layer_target_map;
191 }
192 int32_t zmap::getLayerTargetScr()
193 {
194 return layer_target_scr;
195 }
196 int32_t zmap::getLayerTargetMultiple()
197 {
198 return layer_target_multiple;
199 }
200 bool zmap::isDungeon(int32_t scr)
201 {
202 for(int32_t i=0; i<4; i++)
203 {
204 if(screens[scr].data[i]!=screens[TEMPLATE].data[i])
205 {
206 return false;
207 }
208 }
209
210 return true;
211 }
212
213 bool zmap::clearall(bool validate)
214 {
215 Color=0;
216 char tbuf[10];
217
218 if((header.templatepath[0]!=0)&&validate)
219 {
220 if(!valid_zqt(header.templatepath))
221 {
222 jwin_alert("Error","Invalid Quest Template",NULL,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
223 return false;
224 }
225 }
226
227 for(int32_t i=0; i<map_count; i++)
228 {
229 setCurrMap(i);
230 sprintf(tbuf, "%d", i);
231 clearmap(true);
232 }
233
234 setCurrMap(0);
235 return true;
236 }
237
238 bool zmap::reset_templates(bool validate)
239 {
240 //why are we doing this?
241 if(colordata==NULL)
242 {
243 return false;
244 }
245
246 //int32_t ret;
247 word version, build, dummy, sversion=0;
248 byte dummyc;
249 word dummyw;
250 //int32_t section_size;
251 word temp_map_count;
252 mapscr temp_mapscr;
253 PACKFILE *f=NULL;
254
255 // setPackfilePassword(datapwd);
256 f=open_quest_template(&header, "modules/classic/default.qst", validate);
257 get_version_and_build(f, &version, &build);
258
259 if(!find_section(f, ID_MAPS))
260 {
261 // setPackfilePassword(NULL);
262 return false;
263 }
264
265 //section version info
266 if(!p_igetw(&sversion,f))
267 {
268 return false;
269 }
270
271 if(!p_igetw(&dummy,f))
272 {
273 return false;
274 }
275
276 //section size
277 dword dummy_size;
278 if(!p_igetl(&dummy_size,f))
279 {
280 return false;
281 }
282
283 //finally... section data
284 if(!p_igetw(&temp_map_count,f))
285 {
286 return false;
287 }
288
289 if(version>12)
290 {
291 if(!p_getc(&dummyc,f))
292 return qe_invalid;
293
294 if(!p_getc(&dummyc,f))
295 return qe_invalid;
296
297 if(!p_igetw(&dummyw,f))
298 return qe_invalid;
299
300 if(!p_igetw(&dummyw,f))
301 return qe_invalid;
302
303 if(!p_igetw(&dummyw,f))
304 return qe_invalid;
305
306 if(!p_igetw(&dummyw,f))
307 return qe_invalid;
308
309 if(!p_igetw(&dummyw,f))
310 return qe_invalid;
311
312 if(!p_igetw(&dummyw,f))
313 return qe_invalid;
314
315 if(!p_igetw(&dummyw,f))
316 return qe_invalid;
317
318 if(!p_igetw(&dummyw,f))
319 return qe_invalid;
320
321 if(!p_igetw(&dummyw,f))
322 return qe_invalid;
323
324 if(!p_igetw(&dummyw,f))
325 return qe_invalid;
326
327 if(!p_getc(&dummyc,f))
328 return qe_invalid;
329
330 if(!p_getc(&dummyc,f))
331 return qe_invalid;
332 }
333
334 for(int32_t i=0; i<MAPSCRSNORMAL; ++i)
335 {
336 readmapscreen(f, &header, &temp_mapscr, sversion);
337 }
338
339 readmapscreen(f, &header, &TheMaps[128], sversion);
340 readmapscreen(f, &header, &TheMaps[129], sversion);
341
342 for(int32_t i=0; i<(MAPSCRS-(MAPSCRSNORMAL+2)); ++i)
343 {
344 readmapscreen(f, &header, &temp_mapscr, sversion);
345 }
346
347 if(version>12)
348 {
349 if(!p_getc(&dummyc,f))
350 return qe_invalid;
351
352 if(!p_getc(&dummyc,f))
353 return qe_invalid;
354
355 if(!p_igetw(&dummyw,f))
356 return qe_invalid;
357
358 if(!p_igetw(&dummyw,f))
359 return qe_invalid;
360
361 if(!p_igetw(&dummyw,f))
362 return qe_invalid;
363
364 if(!p_igetw(&dummyw,f))
365 return qe_invalid;
366
367 if(!p_igetw(&dummyw,f))
368 return qe_invalid;
369
370 if(!p_igetw(&dummyw,f))
371 return qe_invalid;
372
373 if(!p_igetw(&dummyw,f))
374 return qe_invalid;
375
376 if(!p_igetw(&dummyw,f))
377 return qe_invalid;
378
379 if(!p_igetw(&dummyw,f))
380 return qe_invalid;
381
382 if(!p_igetw(&dummyw,f))
383 return qe_invalid;
384
385 if(!p_getc(&dummyc,f))
386 return qe_invalid;
387
388 if(!p_getc(&dummyc,f))
389 return qe_invalid;
390 }
391
392 for(int32_t i=0; i<MAPSCRSNORMAL; ++i)
393 {
394 readmapscreen(f, &header, &temp_mapscr, sversion);
395 }
396
397 readmapscreen(f, &header, &TheMaps[MAPSCRS+128], sversion);
398 readmapscreen(f, &header, &TheMaps[MAPSCRS+129], sversion);
399
400 pack_fclose(f);
401 clear_quest_tmpfile();
402
403 return true;
404 }
405
406 bool zmap::clearmap(bool newquest)
407 {
408 if(cursor.map<map_count)
409 {
410 for(int32_t i=0; i<MAPSCRS-(newquest?0:TEMPLATES); i++)
411 {
412 clearscr(i);
413 }
414
415 setCurrScr(0);
416
417 if(newquest)
418 {
419 if(!reset_templates(false))
420 {
421 jwin_alert("Error","Error resetting","template screens.",NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
422 }
423 }
424 }
425
426 return true;
427 }
428
429 MapCursor zmap::getCursor() const
430 {
431 return cursor;
432 }
433
434 11 void zmap::setCursor(MapCursor new_cursor)
435 {
436
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
11 if (cursor == new_cursor && screens)
437 return;
438
439
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 if (screens)
440 pushCursorToHistory(std::move(cursor));
441 11 cursor = std::move(new_cursor);
442
443
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 if (!screens) Color = -1;
444 11 screens = &TheMaps[cursor.map*MAPSCRS];
445
446 11 refresh_color();
447 11 setlayertarget();
448 11 reset_combo_animations2();
449 11 mmap_mark_dirty();
450 11 regions_mark_dirty();
451 11 }
452
453 void zmap::pushCursorToHistory(MapCursor cursor)
454 {
455 if (cursor_history_enabled)
456 {
457 cursor_undo_stack.push_back(std::move(cursor));
458 cursor_redo_stack = {};
459 CapCursorHistory();
460 }
461 }
462
463 bool zmap::isValidPosition(ComboPosition pos) const
464 {
465 return pos.is_valid(cursor);
466 }
467
468 int zmap::getScreenForPosition(ComboPosition pos) const
469 {
470 return cursor.viewscr + pos.screen_offset();
471 }
472
473 mapscr* zmap::CurrScr()
474 {
475 return screens+cursor.screen;
476 }
477 mapscr* zmap::Scr(int32_t scr)
478 {
479 return screens+scr;
480 }
481 mapscr* zmap::Scr(ComboPosition pos)
482 {
483 if (!pos.is_valid(cursor))
484 return nullptr;
485
486 int screen_offset = pos.screen_offset();
487 int screen = cursor.viewscr + screen_offset;
488 return AbsoluteScr(cursor.map, screen);
489 }
490 mapscr* zmap::Scr(ComboPosition pos, int layer)
491 {
492 int map = cursor.map;
493 int screen = cursor.viewscr + pos.screen_offset();
494 if (layer)
495 {
496 mapscr* scr = Map.AbsoluteScr(map, screen);
497 map = scr->layermap[CurrentLayer-1]-1;
498 screen = scr->layerscreen[CurrentLayer-1];
499 }
500
501 return AbsoluteScr(map, screen);
502 }
503 mapscr* zmap::ScrMakeValid(ComboPosition pos, int layer)
504 {
505 mapscr* scr = Scr(pos, layer);
506 if (scr && !(scr->valid&mVALID))
507 {
508 scr->valid |= mVALID;
509 setcolor(Color, scr);
510 }
511 return scr;
512 }
513 mapscr* zmap::AbsoluteScr(int32_t scr)
514 {
515 if(unsigned(scr) >= MAPSCRS*getMapCount())
516 return nullptr;
517 return &TheMaps[scr];
518 }
519 mapscr* zmap::AbsoluteScr(int32_t map, int32_t scr)
520 {
521 if(map < 0 || map >= getMapCount() || scr < 0 || scr >= MAPSCRS)
522 return nullptr;
523 return AbsoluteScr((map*MAPSCRS)+scr);
524 }
525 mapscr* zmap::AbsoluteScrMakeValid(int32_t map, int32_t screen)
526 {
527 mapscr* scr = AbsoluteScr(map, screen);
528 if (scr && !(scr->valid&mVALID))
529 {
530 scr->valid |= mVALID;
531 setcolor(Color, scr);
532 }
533 return scr;
534 }
535 void zmap::set_prvscr(int32_t map, int32_t scr)
536 {
537 prvscr = *get_canonical_scr(map, scr);
538
539 for(int32_t i=0; i<6; i++)
540 {
541 if(prvscr.layermap[i]>0)
542 {
543 prvlayers[i] = *get_canonical_scr(prvscr.layermap[i] - 1, prvscr.layerscreen[i]);
544 }
545 else
546 prvlayers[i].valid = 0;
547 }
548
549 prv_map=map;
550 prv_scr=scr;
551 }
552 92 int32_t zmap::getCurrMap()
553 {
554 92 return cursor.map;
555 }
556 11 void zmap::regions_mark_dirty()
557 {
558 11 regions_dirty = true;
559 11 }
560 void zmap::regions_refresh()
561 {
562 if (!regions_dirty)
563 return;
564
565 regions_dirty = false;
566 region_descriptions.clear();
567
568 current_map_region_ids = Regions[cursor.map].get_all_region_ids();
569 if (!get_all_region_descriptions(region_descriptions, current_map_region_ids))
570 region_descriptions.clear();
571 }
572 const std::vector<region_description>& zmap::get_region_descriptions()
573 {
574 regions_refresh();
575 return region_descriptions;
576 }
577 bool zmap::is_region(int screen)
578 {
579 if (screen < 0 || screen >= 128)
580 return false;
581
582 regions_refresh();
583 return current_map_region_ids[screen];
584 }
585 bool zmap::isDark(int scr)
586 {
587 return (screens[scr].flags&fDARK)!=0;
588 }
589 bool zmap::isValid(int32_t scr)
590 {
591 return (screens[scr].valid&mVALID)!=0;
592 }
593 bool zmap::isValid(int32_t map, int32_t scr)
594 {
595 return (AbsoluteScr(map, scr)->valid&mVALID)!=0;
596 }
597
598 void zmap::setCurrMap(int32_t index)
599 {
600 scrpos[cursor.map] = cursor.screen;
601 scrview[cursor.map] = cursor.viewscr;
602
603 auto new_cursor = cursor;
604 new_cursor.map = bound(index,0,map_count);
605
606 new_cursor.viewscr = scrview[new_cursor.map];
607 new_cursor.setScreen(scrpos[new_cursor.map]);
608 setCursor(std::move(new_cursor));
609 }
610
611 20 int32_t zmap::getCurrScr()
612 {
613 20 return cursor.screen;
614 }
615 void zmap::setCurrScr(int32_t scr)
616 {
617 if (scr == cursor.screen)
618 return;
619
620 auto new_cursor = cursor;
621 new_cursor.setScreen(scr);
622 setCursor(std::move(new_cursor));
623 }
624
625 int32_t zmap::getViewScr()
626 {
627 return cursor.viewscr;
628 }
629
630 void zmap::setViewSize(int32_t size)
631 {
632 auto new_cursor = cursor;
633 new_cursor.setSize(size);
634 setCursor(std::move(new_cursor));
635 }
636
637 1 int32_t zmap::getViewSize()
638 {
639 1 return cursor.size;
640 }
641
642 11 void zmap::setlayertarget()
643 {
644 11 layer_target_map = 0;
645 11 layer_target_multiple = 0;
646
647
2/2
✓ Branch 0 taken 56 times.
✓ Branch 1 taken 11 times.
67 for(int32_t m=0; m<getMapCount(); ++m)
648 {
649
2/2
✓ Branch 0 taken 7616 times.
✓ Branch 1 taken 56 times.
7672 for(int32_t s=0; s<MAPSCRS; ++s)
650 {
651 7616 int32_t i=(m*MAPSCRS+s);
652 7616 mapscr *ts=&TheMaps[i];
653
654 // Search through each layer
655
2/2
✓ Branch 0 taken 45696 times.
✓ Branch 1 taken 7616 times.
53312 for(int32_t w=0; w<6; ++w)
656 {
657
3/4
✓ Branch 0 taken 15868 times.
✓ Branch 1 taken 29828 times.
✓ Branch 2 taken 15868 times.
✗ Branch 3 not taken.
45696 if(ts->layerscreen[w]==cursor.screen && (ts->layermap[w]-1)==cursor.map)
658 {
659 if(layer_target_map > 0)
660 {
661 layer_target_multiple += 1;
662 continue;
663 }
664
665 layer_target_map = m+1;
666 layer_target_scr = s;
667 }
668 45696 }
669 7616 }
670 56 }
671 11 }
672
673 11 void zmap::refresh_color()
674 {
675 11 auto color = getcolor();
676
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
11 if (Color != color)
677 {
678 11 loadlvlpal(color);
679 11 rebuild_trans_table();
680 11 }
681 11 }
682
683 void zmap::setcolor(int color, mapscr* scr)
684 {
685 if (!scr)
686 scr = CurrScr();
687 scr->valid |= mVALID;
688 scr->color = color;
689
690 refresh_color();
691
692 mmap_mark_dirty();
693 }
694
695 11 int32_t zmap::getcolor()
696 {
697 11 return getcolor(cursor.screen);
698 }
699
700 11 int32_t zmap::getcolor(int screen)
701 {
702
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 mapscr& scr = prv_mode ? prvscr : screens[screen];
703
704
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 if (scr.valid & mVALID)
705 11 return scr.color;
706
707 return map_infos[cursor.map].autopalette;
708 11 }
709
710 void zmap::resetflags()
711 {
712 byte *di=&(screens[cursor.screen].valid);
713
714 for(int32_t i=1; i<48; i++)
715 {
716 *(di+i)=0;
717 }
718 }
719
720 word zmap::tcmbdat(int32_t pos)
721 {
722 return screens[TEMPLATE].data[pos];
723 }
724
725 word zmap::tcmbcset(int32_t pos)
726 {
727 return screens[TEMPLATE].cset[pos];
728 }
729
730 int32_t zmap::tcmbflag(int32_t pos)
731 {
732 return screens[TEMPLATE].sflag[pos];
733 }
734
735 word zmap::tcmbdat2(int32_t pos)
736 {
737 return screens[TEMPLATE2].data[pos];
738 }
739
740 word zmap::tcmbcset2(int32_t pos)
741 {
742 return screens[TEMPLATE2].cset[pos];
743 }
744
745 int32_t zmap::tcmbflag2(int32_t pos)
746 {
747 return screens[TEMPLATE2].sflag[pos];
748 }
749
750 void zmap::TemplateAll()
751 {
752 StartListCommand();
753 for(int32_t i=0; i<128; i++)
754 {
755 if((screens[i].valid&mVALID) && isDungeon(i))
756 DoTemplateCommand(-1, -1, i);
757 }
758 FinishListCommand();
759 }
760
761 void zmap::Template(int32_t floorcombo, int32_t floorcset, int32_t scr)
762 {
763 if(scr==TEMPLATE)
764 return;
765
766 if(!(screens[scr].valid&mVALID))
767 screens[scr].color=Color;
768
769 screens[scr].valid|=mVALID;
770
771 for(int32_t i=0; i<32; i++)
772 {
773 screens[scr].data[i]=screens[TEMPLATE].data[i];
774 screens[scr].cset[i]=screens[TEMPLATE].cset[i];
775 screens[scr].sflag[i]=screens[TEMPLATE].sflag[i];
776 }
777
778 for(int32_t i=144; i<176; i++)
779 {
780 screens[scr].data[i]=screens[TEMPLATE].data[i];
781 screens[scr].cset[i]=screens[TEMPLATE].cset[i];
782 screens[scr].sflag[i]=screens[TEMPLATE].sflag[i];
783 }
784
785 for(int32_t y=2; y<=9; y++)
786 {
787 int32_t j=y<<4;
788 screens[scr].data[j]=screens[TEMPLATE].data[j];
789 screens[scr].cset[j]=screens[TEMPLATE].cset[j];
790 screens[scr].sflag[j]=screens[TEMPLATE].sflag[j];
791 ++j;
792 screens[scr].data[j]=screens[TEMPLATE].data[j];
793 screens[scr].cset[j]=screens[TEMPLATE].cset[j];
794 screens[scr].sflag[j]=screens[TEMPLATE].sflag[j];
795 ++j;
796 j+=12;
797 screens[scr].data[j]=screens[TEMPLATE].data[j];
798 screens[scr].cset[j]=screens[TEMPLATE].cset[j];
799 screens[scr].sflag[j]=screens[TEMPLATE].sflag[j];
800 ++j;
801 screens[scr].data[j]=screens[TEMPLATE].data[j];
802 screens[scr].cset[j]=screens[TEMPLATE].cset[j];
803
804 screens[scr].sflag[j]=screens[TEMPLATE].sflag[j];
805 ++j;
806 }
807
808 if(floorcombo!=-1)
809 {
810 for(int32_t y=2; y<9; y++)
811 for(int32_t x=2; x<14; x++)
812 {
813 int32_t i=(y<<4)+x;
814 screens[scr].data[i] = floorcombo;
815 screens[scr].cset[i] = floorcset;
816 }
817 }
818
819 for(int32_t i=0; i<4; i++)
820 putdoor(scr,i,screens[scr].door[i]);
821 }
822
823
824 void zmap::clearscr(int32_t scr)
825 {
826 screens[scr].zero_memory();
827 screens[scr].valid=mVERSION;
828 auto const& mapinf = map_infos[cursor.map];
829 for(int q = 0; q < 6; ++q)
830 {
831 auto layer = mapinf.autolayers[q];
832 screens[scr].layermap[q] = layer;
833 screens[scr].layerscreen[q] = layer ? scr : 0;
834 }
835 screens[scr].color = mapinf.autopalette;
836 if (scr == cursor.screen)
837 refresh_color();
838 mmap_mark_dirty();
839 }
840
841 const char *loaderror[] =
842 {
843
844 "OK","File not found","Incomplete data",
845 "Invalid version","Invalid file"
846
847 };
848
849 int32_t zmap::load(const char *path)
850 {
851 PACKFILE *f=pack_fopen_password(path,F_READ, "");
852
853 if(!f)
854 return 1;
855
856
857 int16_t version;
858 byte build;
859
860 //get the version
861 if(!p_igetw(&version,f))
862 {
863 goto file_error;
864 }
865
866 //get the build
867 if(!p_getc(&build,f))
868 {
869 goto file_error;
870 }
871
872 for(int32_t i=0; i<MAPSCRS; i++)
873 {
874 mapscr tmpimportscr;
875 tmpimportscr.zero_memory();
876 if(readmapscreen(f,&header,&tmpimportscr,version)==qe_invalid)
877 {
878 al_trace("failed zmap::load\n");
879 goto file_error;
880 }
881
882 switch(ImportMapBias)
883 {
884 case 0:
885 *(screens+i) = tmpimportscr;
886 break;
887
888 case 1:
889 if(!(screens[i].valid&mVALID))
890 {
891 *(screens+i) = tmpimportscr;
892 }
893 break;
894
895 case 2:
896 if(tmpimportscr.valid&mVALID)
897 {
898 *(screens+i) = tmpimportscr;
899 }
900 break;
901 }
902 }
903
904
905 pack_fclose(f);
906
907 setCurrScr(0);
908 mmap_mark_dirty();
909 regions_mark_dirty();
910 return 0;
911
912 file_error:
913 pack_fclose(f);
914 clearmap(false);
915 return 2;
916 }
917
918 int32_t zmap::save(const char *path)
919 {
920 PACKFILE *f=pack_fopen_password(path,F_WRITE, "");
921
922 if(!f)
923 return 1;
924
925 if(!p_iputw(V_MAPS,f))
926 {
927 pack_fclose(f);
928 return 3;
929 }
930
931 // This was the "build number", but that's totally useless here. Keep this junk byte
932 // so as not to totally break exports between ZC versions.
933 if(!p_putc(0,f))
934 {
935 pack_fclose(f);
936 return 3;
937 }
938
939 for(int32_t i=0; i<MAPSCRS; i++)
940 {
941 if(writemapscreen(f,this->getCurrMap(),i) == qe_invalid)
942 {
943 pack_fclose(f);
944 return 2;
945 }
946 }
947
948 pack_fclose(f);
949 return 0;
950 }
951
952
953 bool zmap::ishookshottable(int32_t bx, int32_t by, int32_t i)
954 {
955 // Hookshots can be blocked by solid combos on all 3 ground layers.
956 const newcombo* c = &combobuf[MAPCOMBO(bx,by)];
957
958 if(c->type == cHOOKSHOTONLY || c->type == cLADDERHOOKSHOT)
959 return true;
960 if (c->walk&(1<<i))
961 return false;
962
963 for(int32_t k=0; k<2; k++)
964 {
965 c = &combobuf[MAPCOMBO2(k+1,bx,by)];
966
967 if(c->type != cHOOKSHOTONLY && c->type != cLADDERHOOKSHOT && c->walk&(1<<i))
968 {
969 return false;
970 }
971 }
972
973 return true;
974 }
975
976 bool zmap::ishookshottable(int32_t map, int32_t screen, int32_t bx, int32_t by, int32_t i)
977 {
978 // Hookshots can be blocked by solid combos on all 3 ground layers.
979 const newcombo* c = &combobuf[MAPCOMBO3(map, screen, -1, bx,by)];
980
981 if(c->type == cHOOKSHOTONLY || c->type == cLADDERHOOKSHOT)
982 return true;
983 if (c->walk&(1<<i))
984 return false;
985
986 for(int32_t k=0; k<2; k++)
987 {
988 c = &combobuf[MAPCOMBO3(map, screen, k+1,bx,by)];
989
990 if(c->type != cHOOKSHOTONLY && c->type != cLADDERHOOKSHOT && c->walk&(1<<i))
991 {
992 return false;
993 }
994 }
995
996 return true;
997 }
998
999 bool zmap::isstepable(int32_t combo)
1000 {
1001 // This is kind of odd but it's true to the engine (see maps.cpp)
1002 return (combo_class_buf[combobuf[combo].type].ladder_pass);
1003 }
1004
1005 // Returns the letter of the warp combo.
1006 int32_t zmap::warpindex(int32_t combo)
1007 {
1008 switch(combobuf[combo].type)
1009 {
1010 case cCAVE:
1011 case cPIT:
1012 case cSTAIR:
1013 case cCAVE2:
1014 case cSWIMWARP:
1015 case cDIVEWARP:
1016 case cSWARPA:
1017 return 0;
1018
1019 case cCAVEB:
1020 case cPITB:
1021 case cSTAIRB:
1022 case cCAVE2B:
1023 case cSWIMWARPB:
1024 case cDIVEWARPB:
1025 case cSWARPB:
1026 return 1;
1027
1028 case cCAVEC:
1029 case cPITC:
1030 case cSTAIRC:
1031 case cCAVE2C:
1032 case cSWIMWARPC:
1033 case cDIVEWARPC:
1034 case cSWARPC:
1035 return 2;
1036
1037 case cCAVED:
1038 case cPITD:
1039 case cSTAIRD:
1040 case cCAVE2D:
1041 case cSWIMWARPD:
1042 case cDIVEWARPD:
1043 case cSWARPD:
1044 return 3;
1045
1046 case cPITR:
1047 case cSTAIRR:
1048 case cSWARPR:
1049 return 4;
1050 }
1051
1052 return -1;
1053
1054 }
1055
1056 void draw_ladder(BITMAP* dest, int32_t x, int32_t y, int32_t c, bool top = false)
1057 {
1058 if(top)
1059 line(dest,x,y,x+15,y,c);
1060 rectfill(dest,x,y,x+3,y+15,c);
1061 rectfill(dest,x+12,y,x+15,y+15,c);
1062 rectfill(dest,x+4,y+2,x+11,y+5,c);
1063 rectfill(dest,x+4,y+10,x+11,y+13,c);
1064 }
1065
1066 void draw_platform(BITMAP* dest, int32_t x, int32_t y, int32_t c)
1067 {
1068 line(dest,x,y,x+15,y,c);
1069 }
1070
1071 void zmap::put_walkflags_layered(BITMAP *dest,int32_t x,int32_t y,int32_t pos,int32_t layer)
1072 {
1073 int32_t cx = COMBOX(pos);
1074 int32_t cy = COMBOY(pos);
1075
1076 newcombo const& c = combobuf[ MAPCOMBO2(layer,cx,cy) ];
1077
1078 if (c.type == cBRIDGE && get_qr(qr_OLD_BRIDGE_COMBOS)) return;
1079
1080 int32_t bridgedetected = 0;
1081
1082 for(int32_t i=0; i<4; i++)
1083 {
1084 int32_t tx=((i&2)<<2)+x;
1085 int32_t ty=((i&1)<<3)+y;
1086 int32_t tx2=((i&2)<<2)+cx;
1087 int32_t ty2=((i&1)<<3)+cy;
1088 for (int32_t m = layer; m <= 1; m++)
1089 {
1090 if (get_qr(qr_OLD_BRIDGE_COMBOS))
1091 {
1092 if (combobuf[MAPCOMBO2(m,tx2,ty2)].type == cBRIDGE && !(combobuf[MAPCOMBO2(m,tx2,ty2)].walk&(1<<i)))
1093 {
1094 bridgedetected |= (1<<i);
1095 }
1096 }
1097 else
1098 {
1099 if (combobuf[MAPCOMBO2(m,tx2,ty2)].type == cBRIDGE && (combobuf[MAPCOMBO2(m,tx2,ty2)].walk&(0x10<<i)))
1100 {
1101 bridgedetected |= (1<<i);
1102 }
1103 }
1104 }
1105 if (bridgedetected & (1<<i))
1106 {
1107 if (i >= 3) break;
1108 else continue;
1109 }
1110 if ((c.walk&(1<<(i+4))) && ((c.walk&(1<<i) && ((c.usrflags&cflag4)) && c.type == cWATER) || c.type == cSHALLOWWATER))
1111 {
1112 for(int32_t k=0; k<8; k+=2)
1113 for(int32_t j=0; j<8; j+=2)
1114 if(((k+j)/2)%2) rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(11));
1115 }
1116 if (!(c.walk&(1<<i) && ((c.usrflags&cflag3) || (c.usrflags&cflag4))) && (layer==-1 || (get_qr(qr_WATER_ON_LAYER_1) && layer == 0) || (get_qr(qr_WATER_ON_LAYER_2) && layer == 1)) && combo_class_buf[c.type].water!=0 && get_qr(qr_DROWN))
1117 rectfill(dest,tx,ty,tx+7,ty+7,vc(11));
1118
1119 if(c.walk&(1<<i) && !(combo_class_buf[c.type].water!=0 && ((c.usrflags&cflag3) || (c.usrflags&cflag4))))
1120 {
1121 if(c.type==cLADDERHOOKSHOT && isstepable(MAPCOMBO(cx,cy)) && ishookshottable(cx,cy,i))
1122 {
1123 for(int32_t k=0; k<8; k+=2)
1124 for(int32_t j=0; j<8; j+=2)
1125 rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(6+((k+j)/2)%2));
1126 }
1127 else
1128 {
1129 int32_t color = COLOR_SOLID;
1130
1131 if(isstepable(MAPCOMBO(cx,cy)) && (!get_qr(qr_NO_SOLID_SWIM) || (combo_class_buf[combobuf[MAPCOMBO(cx,cy)].type].water==0 && combo_class_buf[c.type].water==0)))
1132 color=vc(6);
1133 else if((c.type==cHOOKSHOTONLY || c.type==cLADDERHOOKSHOT) && ishookshottable(cx,cy,i))
1134 color=vc(7);
1135
1136 rectfill(dest,tx,ty,tx+7,ty+7,color);
1137 }
1138 }
1139 }
1140
1141 bridgedetected = 0;
1142 for(int32_t i=0; i<4; i++)
1143 {
1144 int32_t tx2=((i&2)<<2)+cx;
1145 int32_t ty2=((i&1)<<3)+cy;
1146 for (int32_t m = 0; m <= 1; m++)
1147 {
1148 if (get_qr(qr_OLD_BRIDGE_COMBOS))
1149 {
1150 if (combobuf[MAPCOMBO2(m,tx2,ty2)].type == cBRIDGE && !(combobuf[MAPCOMBO2(m,tx2,ty2)].walk&(1<<i)))
1151 {
1152 bridgedetected |= (1<<i);
1153 }
1154 }
1155 else
1156 {
1157 if (combobuf[MAPCOMBO2(m,tx2,ty2)].type == cBRIDGE && (combobuf[MAPCOMBO2(m,tx2,ty2)].walk&(0x10<<i)))
1158 {
1159 bridgedetected |= (1<<i);
1160 }
1161 }
1162 }
1163 }
1164
1165 // Draw damage combos
1166 newcombo const& c0 = combobuf[MAPCOMBO2(-1,cx,cy)];
1167 newcombo const& c1 = combobuf[MAPCOMBO2(0,cx,cy)];
1168 newcombo const& c2 = combobuf[MAPCOMBO2(1,cx,cy)];
1169 bool dmg = combo_class_buf[c0.type].modify_hp_amount
1170 || combo_class_buf[c1.type].modify_hp_amount
1171 || combo_class_buf[c2.type].modify_hp_amount;
1172
1173 if (combo_class_buf[c2.type].modify_hp_amount) bridgedetected = 0;
1174
1175 if(dmg)
1176 {
1177 if (bridgedetected <= 0)
1178 {
1179 for(int32_t k=0; k<16; k+=2)
1180 for(int32_t j=0; j<16; j+=2)
1181 if(((k+j)/2)%2)
1182 rectfill(dest,x+k,y+j,x+k+1,y+j+1,vc(14));
1183 }
1184 else
1185 {
1186 for(int32_t i=0; i<4; i++)
1187 {
1188 if (!(bridgedetected & (1<<i)))
1189 {
1190 int32_t tx=((i&2)<<2)+x;
1191 int32_t ty=((i&1)<<3)+y;
1192 for(int32_t k=0; k<8; k+=2)
1193 for(int32_t j=0; j<8; j+=2)
1194 if(((k+j)/2)%2)
1195 rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(14));
1196 }
1197 }
1198 }
1199 }
1200
1201 if(c.type == cSLOPE)
1202 {
1203 slope_info s(c, x, y);
1204 s.draw(dest, 0, 0, COLOR_SLOPE);
1205 }
1206 auto fl0 = MAPFLAG2(-1,cx,cy);
1207 auto fl1 = MAPFLAG2(0,cx,cy);
1208 auto fl2 = MAPFLAG2(1,cx,cy);
1209 if(fl0 == mfSIDEVIEWLADDER || fl1 == mfSIDEVIEWLADDER || fl2 == mfSIDEVIEWLADDER
1210 || c0.flag == mfSIDEVIEWLADDER || c1.flag == mfSIDEVIEWLADDER || c2.flag == mfSIDEVIEWLADDER)
1211 {
1212 bool top = false;
1213 if(cy)
1214 {
1215 top = true;
1216 if(combobuf[MAPCOMBO2(-1,cx,cy-16)].flag == mfSIDEVIEWLADDER
1217 || combobuf[MAPCOMBO2(0,cx,cy-16)].flag == mfSIDEVIEWLADDER
1218 || combobuf[MAPCOMBO2(1,cx,cy-16)].flag == mfSIDEVIEWLADDER
1219 || MAPFLAG2(-1,cx,cy) == mfSIDEVIEWLADDER
1220 || MAPFLAG2(0,cx,cy) == mfSIDEVIEWLADDER
1221 || MAPFLAG2(1,cx,cy) == mfSIDEVIEWLADDER)
1222 {
1223 top = false;
1224 }
1225 }
1226 draw_ladder(dest,x,y,COLOR_LADDER,top);
1227 }
1228 else if(fl0 == mfSIDEVIEWPLATFORM || fl1 == mfSIDEVIEWPLATFORM || fl2 == mfSIDEVIEWPLATFORM
1229 || c0.flag == mfSIDEVIEWPLATFORM || c1.flag == mfSIDEVIEWPLATFORM || c2.flag == mfSIDEVIEWPLATFORM)
1230 {
1231 draw_platform(dest,x,y,COLOR_LADDER);
1232 }
1233 }
1234
1235 void zmap::put_walkflags_layered_external(BITMAP *dest,int32_t x,int32_t y,int32_t pos,int32_t layer, int32_t map, int32_t screen)
1236 {
1237 int32_t cx = COMBOX(pos);
1238 int32_t cy = COMBOY(pos);
1239
1240 if (screen < 0) return;
1241 if (map < 0) return;
1242
1243 newcombo const& c = combobuf[MAPCOMBO3(map, screen, layer, pos)];
1244
1245 if (c.type == cBRIDGE && get_qr(qr_OLD_BRIDGE_COMBOS)) return;
1246
1247 int32_t bridgedetected = 0;
1248 for(int32_t i=0; i<4; i++)
1249 {
1250 int32_t tx=((i&2)<<2)+x;
1251 int32_t ty=((i&1)<<3)+y;
1252 int32_t tx2=((i&2)<<2)+cx;
1253 int32_t ty2=((i&1)<<3)+cy;
1254 for (int32_t m = layer; m <= 1; m++)
1255 {
1256 newcombo const& cmb = combobuf[MAPCOMBO3(map, screen, m,tx2,ty2)];
1257 if (get_qr(qr_OLD_BRIDGE_COMBOS))
1258 {
1259 if (cmb.type == cBRIDGE && !(cmb.walk&(1<<i)))
1260 {
1261 bridgedetected |= (1<<i);
1262 }
1263 }
1264 else
1265 {
1266 if (cmb.type == cBRIDGE && (cmb.walk&(0x10<<i)))
1267 {
1268 bridgedetected |= (1<<i);
1269 }
1270 }
1271 }
1272 if (bridgedetected & (1<<i))
1273 {
1274 continue;
1275 }
1276 if(!(c.walk&(1<<i) && ((c.usrflags&cflag3) || (c.usrflags&cflag4))) && (layer==-1 || (get_qr(qr_WATER_ON_LAYER_1) && layer == 0) || (get_qr(qr_WATER_ON_LAYER_2) && layer == 1)) && combo_class_buf[c.type].water!=0 && get_qr(qr_DROWN))
1277 rectfill(dest,tx,ty,tx+7,ty+7,vc(11));
1278
1279
1280 if ((c.walk&(1<<(i+4))) && ((c.walk&(1<<i) && ((c.usrflags&cflag4)) && c.type == cWATER) || c.type == cSHALLOWWATER))
1281 {
1282 for(int32_t k=0; k<8; k+=2)
1283 for(int32_t j=0; j<8; j+=2)
1284 if(((k+j)/2)%2) rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(11));
1285 }
1286 if(c.walk&(1<<i) && !(combo_class_buf[c.type].water!=0 && ((c.usrflags&cflag3) || (c.usrflags&cflag4))))
1287 {
1288 if(c.type==cLADDERHOOKSHOT && isstepable(MAPCOMBO3(map, screen, layer, cx,cy)) && ishookshottable(map, screen, cx,cy,i) && layer < 0)
1289 {
1290 for(int32_t k=0; k<8; k+=2)
1291 for(int32_t j=0; j<8; j+=2)
1292 rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(6+((k+j)/2)%2));
1293 }
1294 else
1295 {
1296 int32_t color = COLOR_SOLID;
1297
1298 if(isstepable(MAPCOMBO3(map, screen, -1, cx,cy)) && (!get_qr(qr_NO_SOLID_SWIM) || combo_class_buf[combobuf[MAPCOMBO3(map, screen, -1, cx,cy)].type].water==0))
1299 color=vc(6);
1300 else if((c.type==cHOOKSHOTONLY || c.type==cLADDERHOOKSHOT) && ishookshottable(map, screen, cx,cy,i))
1301 color=vc(7);
1302
1303 rectfill(dest,tx,ty,tx+7,ty+7,color);
1304 }
1305 }
1306 }
1307
1308 bridgedetected = 0;
1309 for(int32_t i=0; i<4; i++)
1310 {
1311 int32_t tx2=((i&2)<<2)+cx;
1312 int32_t ty2=((i&1)<<3)+cy;
1313 for (int32_t m = 0; m <= 1; m++)
1314 {
1315 newcombo const& cmb = combobuf[MAPCOMBO3(map, screen, m,tx2,ty2)];
1316 if (get_qr(qr_OLD_BRIDGE_COMBOS))
1317 {
1318 if (cmb.type == cBRIDGE && !(cmb.walk&(1<<i)))
1319 {
1320 bridgedetected |= (1<<i);
1321 }
1322 }
1323 else
1324 {
1325 if (cmb.type == cBRIDGE && (cmb.walk&(0x10<<i)))
1326 {
1327 bridgedetected |= (1<<i);
1328 }
1329 }
1330 }
1331 }
1332
1333 // Draw damage combos
1334 newcombo const& c0 = combobuf[MAPCOMBO3(map, screen, -1,pos)];
1335 newcombo const& c1 = combobuf[MAPCOMBO3(map, screen, 0,pos)];
1336 newcombo const& c2 = combobuf[MAPCOMBO3(map, screen, 1,pos)];
1337 bool dmg = combo_class_buf[c0.type].modify_hp_amount
1338 || combo_class_buf[c1.type].modify_hp_amount
1339 || combo_class_buf[c2.type].modify_hp_amount;
1340
1341 if (combo_class_buf[c2.type].modify_hp_amount) bridgedetected = 0;
1342
1343 if(dmg)
1344 {
1345 if (bridgedetected <= 0)
1346 {
1347 for(int32_t k=0; k<16; k+=2)
1348 for(int32_t j=0; j<16; j+=2)
1349 if(((k+j)/2)%2)
1350 rectfill(dest,x+k,y+j,x+k+1,y+j+1,vc(14));
1351 }
1352 else
1353 {
1354 for(int32_t i=0; i<4; i++)
1355 {
1356 if (!(bridgedetected & (1<<i)))
1357 {
1358 int32_t tx=((i&2)<<2)+x;
1359 int32_t ty=((i&1)<<3)+y;
1360 for(int32_t k=0; k<8; k+=2)
1361 for(int32_t j=0; j<8; j+=2)
1362 if(((k+j)/2)%2)
1363 rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(14));
1364 }
1365 }
1366 }
1367 }
1368
1369 if(c.type == cSLOPE)
1370 {
1371 slope_info s(c, x, y);
1372 s.draw(dest, 0, 0, COLOR_SLOPE);
1373 }
1374 auto fl0 = MAPFLAG3(map,screen,-1,pos);
1375 auto fl1 = MAPFLAG3(map,screen,0,pos);
1376 auto fl2 = MAPFLAG3(map,screen,1,pos);
1377 if(fl0 == mfSIDEVIEWLADDER || fl1 == mfSIDEVIEWLADDER || fl2 == mfSIDEVIEWLADDER
1378 || c0.flag == mfSIDEVIEWLADDER || c1.flag == mfSIDEVIEWLADDER || c2.flag == mfSIDEVIEWLADDER)
1379 {
1380 bool top = false;
1381 if(cy)
1382 {
1383 top = true;
1384 if(combobuf[MAPCOMBO3(map,screen,-1,cx,cy-16)].flag == mfSIDEVIEWLADDER
1385 || combobuf[MAPCOMBO3(map,screen,0,cx,cy-16)].flag == mfSIDEVIEWLADDER
1386 || combobuf[MAPCOMBO3(map,screen,1,cx,cy-16)].flag == mfSIDEVIEWLADDER
1387 || MAPFLAG3(map,screen,-1,cx,cy-16) == mfSIDEVIEWLADDER
1388 || MAPFLAG3(map,screen,0,cx,cy-16) == mfSIDEVIEWLADDER
1389 || MAPFLAG3(map,screen,1,cx,cy-16) == mfSIDEVIEWLADDER)
1390 {
1391 top = false;
1392 }
1393 }
1394 draw_ladder(dest,x,y,COLOR_LADDER,top);
1395 }
1396 else if(fl0 == mfSIDEVIEWPLATFORM || fl1 == mfSIDEVIEWPLATFORM || fl2 == mfSIDEVIEWPLATFORM
1397 || c0.flag == mfSIDEVIEWPLATFORM || c1.flag == mfSIDEVIEWPLATFORM || c2.flag == mfSIDEVIEWPLATFORM)
1398 {
1399 draw_platform(dest,x,y,COLOR_LADDER);
1400 }
1401 }
1402
1403 void put_walkflags(BITMAP *dest,int32_t x,int32_t y,word cmbdat,int32_t layer)
1404 {
1405 const newcombo& c = combobuf[cmbdat];
1406
1407 if (c.type == cBRIDGE && get_qr(qr_OLD_BRIDGE_COMBOS)) return;
1408
1409 for(int32_t i=0; i<4; i++)
1410 {
1411 int32_t tx=((i&2)<<2)+x;
1412 int32_t ty=((i&1)<<3)+y;
1413
1414 if(!(c.walk&(1<<i) && ((c.usrflags&cflag3) || (c.usrflags&cflag4))) && combo_class_buf[c.type].water!=0)
1415 {
1416 if ((layer==0 || (get_qr(qr_WATER_ON_LAYER_1) && layer == 1) || (get_qr(qr_WATER_ON_LAYER_2) && layer == 2)) && get_qr(qr_DROWN))
1417 {
1418 rectfill(dest,tx,ty,tx+7,ty+7,vc(11));
1419 }
1420 else
1421 {
1422 rectfill(dest,tx,ty,tx+7,ty+7,vc(11));
1423 }
1424 }
1425
1426
1427 if ((c.walk&(1<<(i+4))) && ((c.walk&(1<<i) && ((c.usrflags&cflag4)) && c.type == cWATER) || c.type == cSHALLOWWATER))
1428 {
1429 for(int32_t k=0; k<8; k+=2)
1430 for(int32_t j=0; j<8; j+=2)
1431 if(((k+j)/2)%2) rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(11));
1432 }
1433 if(c.walk&(1<<i) && !(combo_class_buf[c.type].water!=0 && ((c.usrflags&cflag3) || (c.usrflags&cflag4))))
1434 {
1435 if(c.type==cLADDERHOOKSHOT)
1436 {
1437 for(int32_t k=0; k<8; k+=2)
1438 for(int32_t j=0; j<8; j+=2)
1439 rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(6+((k+j)/2)%2));
1440 }
1441 else
1442 {
1443 int32_t color = COLOR_SOLID;
1444
1445 if(c.type==cLADDERONLY)
1446 color=vc(6);
1447 else if(c.type==cHOOKSHOTONLY)
1448 color=vc(7);
1449
1450 rectfill(dest,tx,ty,tx+7,ty+7,color);
1451 }
1452 }
1453
1454 // Draw damage combos
1455 if(combo_class_buf[c.type].modify_hp_amount != 0)
1456 {
1457 for(int32_t k=0; k<8; k+=2)
1458 for(int32_t j=0; j<8; j+=2)
1459 if(((k+j)/2)%2) rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(4));
1460 }
1461 }
1462
1463 if(c.type == cSLOPE)
1464 {
1465 slope_info s(c, 0, 0);
1466 zfix const& slope = s.slope();
1467
1468 BITMAP* sub = create_bitmap_ex(8,16,16);
1469 clear_bitmap(sub);
1470 s.draw(sub, 0, 0, COLOR_SLOPE);
1471 masked_blit(sub, dest, 0, 0, x, y, 16, 16);
1472 destroy_bitmap(sub);
1473 }
1474 if(c.flag == mfSIDEVIEWLADDER)
1475 {
1476 draw_ladder(dest,x,y,COLOR_LADDER);
1477 }
1478 else if(c.flag == mfSIDEVIEWPLATFORM)
1479 {
1480 draw_platform(dest,x,y,COLOR_LADDER);
1481 }
1482 }
1483
1484 void put_flag(BITMAP* dest, int32_t x, int32_t y, int32_t flag)
1485 {
1486 rectfill(dest,x,y,x+15,y+15,vc(flag&15));
1487 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+1,y+1,vc(15-(flag&15)),-1,"%d",flag);
1488 }
1489 void put_flags(BITMAP *dest,int32_t x,int32_t y,word cmbdat,int32_t cset,int32_t flags,int32_t sflag)
1490 {
1491
1492 newcombo const& c = combobuf[cmbdat];
1493
1494 if((flags&cFLAGS)&&(sflag||combobuf[cmbdat].flag))
1495 {
1496 // rectfill(dest,x,y,x+15,y+15,vc(cmbdat>>10+1));
1497 // text_mode(-1);
1498 // textprintf_ex(dest,get_zc_font(font_sfont),x+1,y+1,(sflag)==0x7800?vc(0):vc(15),-1,"%d",sflag);
1499 if(sflag)
1500 {
1501 rectfill(dest,x,y,x+15,y+15,vc(sflag&15));
1502 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+1,y+1,vc(15-(sflag&15)),-1,"%d",sflag);
1503 }
1504
1505 if(c.flag)
1506 {
1507 rectfill(dest,x,y+(sflag?8:0),x+15,y+15,vc((combobuf[cmbdat].flag)&15));
1508 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+1,y+9,vc(15-((combobuf[cmbdat].flag)&15)),-1,"%d",combobuf[cmbdat].flag);
1509 }
1510 }
1511
1512 if(flags&cCSET)
1513 {
1514 bool inv = (((cmbdat&0x7800)==0x7800)&&(flags&cFLAGS));
1515 // text_mode(inv?vc(15):vc(0));
1516 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+9,y+9,inv?vc(0):vc(15),inv?vc(15):vc(0),"%d",cset);
1517 }
1518 else if(flags&cCTYPE)
1519 {
1520 bool inv = (((cmbdat&0x7800)==0x7800)&&(flags&cFLAGS));
1521 // text_mode(inv?vc(15):vc(0));
1522 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+1,y+9,inv?vc(0):vc(15),inv?vc(15):vc(0),"%d",c.type);
1523 }
1524 }
1525
1526 void put_combo(BITMAP *dest,int32_t x,int32_t y,word cmbdat,int32_t cset,int32_t flags,int32_t sflag,int32_t scale)
1527 {
1528 bool repos = combotile_override_x < 0 && combotile_override_y < 0;
1529
1530 BITMAP* b = create_bitmap_ex(8,scale*16,scale*16);
1531 if(repos)
1532 {
1533 combotile_override_x = x+(8*(scale-1));
1534 combotile_override_y = y+(8*(scale-1));
1535 }
1536 put_combo(b,0,0,cmbdat,cset,flags,sflag);
1537 if(repos) combotile_override_x = combotile_override_y = -1;
1538 masked_stretch_blit(b,dest,0,0,16,16,x,y,16*scale,16*scale);
1539 destroy_bitmap(b);
1540 }
1541 void put_combo(BITMAP *dest,int32_t x,int32_t y,word cmbdat,int32_t cset,int32_t flags,int32_t sflag)
1542 {
1543 static newcombo nilcombo;
1544 nilcombo.tile = 0;
1545
1546 newcombo const& c = cmbdat < MAXCOMBOS ? combobuf[cmbdat] : nilcombo;
1547
1548 if(c.tile==0)
1549 {
1550 rectfill(dest,x,y,x+15,y+15,vc(0));
1551 rectfill(dest,x+3,y+3,x+12,y+12,vc(4));
1552 return;
1553 }
1554
1555 putcombo(dest,x,y,cmbdat,cset);
1556
1557 if((flags&cFLAGS)&&(sflag||combobuf[cmbdat].flag))
1558 {
1559 if(sflag)
1560 {
1561 rectfill(dest,x,y,x+15,y+15,vc(sflag&15));
1562 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+1,y+1,vc(15-(sflag&15)),-1,"%d",sflag);
1563 }
1564
1565 if(combobuf[cmbdat].flag)
1566 {
1567 rectfill(dest,x,y+(sflag?8:0),x+15,y+15,vc((combobuf[cmbdat].flag)&15));
1568 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+1,y+1,vc(15-((combobuf[cmbdat].flag)&15)),-1,"%d",combobuf[cmbdat].flag);
1569 }
1570 }
1571
1572 if(flags&cWALK)
1573 {
1574 put_walkflags(dest,x,y,cmbdat,0);
1575 }
1576
1577 if(flags&cCSET)
1578 {
1579 bool inv = (((cmbdat&0x7800)==0x7800)&&(flags&cFLAGS));
1580 // text_mode(inv?vc(15):vc(0));
1581 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+9,y+9,inv?vc(0):vc(15),inv?vc(15):vc(0),"%d",cset);
1582 }
1583 else if(flags&cCTYPE)
1584 {
1585 bool inv = (((cmbdat&0x7800)==0x7800)&&(flags&cFLAGS));
1586 // text_mode(inv?vc(15):vc(0));
1587 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+1,y+9,inv?vc(0):vc(15),inv?vc(15):vc(0),"%d",c.type);
1588 }
1589 }
1590 void put_engraving(BITMAP* dest, int32_t x, int32_t y, int32_t slot, int32_t scale)
1591 {
1592 auto blitx = 1 + (slot % 16) * 17;
1593 auto blity = 1 + (slot / 16) * 17;
1594 masked_stretch_blit(asset_engravings_bmp, dest, blitx, blity, 16, 16, x, y, 16 * scale, 16 * scale);
1595 }
1596
1597
1598 void copy_mapscr(mapscr *dest, const mapscr *src)
1599 {
1600 if(!dest || !src) return;
1601 *dest = *src;
1602 }
1603
1604 void zmap::put_door(BITMAP *dest,int32_t pos,int32_t side,int32_t type,int32_t xofs,int32_t yofs,bool ignorepos, int32_t scr)
1605 {
1606 int32_t x=0,y=0;
1607 mapscr *doorscreen=(prv_mode?get_prvscr():screens+scr);
1608
1609 switch(side)
1610 {
1611 case up:
1612 case down:
1613 x=((pos&15)<<4)+xofs;
1614 y=(ignorepos?0:(pos&0xF0))+yofs;
1615 break;
1616
1617 case left:
1618 case right:
1619 x=(ignorepos?0:((pos&15)<<4))+xofs;
1620 y=(pos&0xF0)+yofs;
1621 break;
1622 }
1623
1624 switch(type)
1625 {
1626 case dt_lock:
1627 case dt_shut:
1628 case dt_boss:
1629 case dt_bomb:
1630 switch(side)
1631 {
1632 case up:
1633 put_combo(dest,x,y,DoorComboSets[doorscreen->door_combo_set].doorcombo_u[type][0],
1634 DoorComboSets[doorscreen->door_combo_set].doorcset_u[type][0],0,0);
1635 put_combo(dest,x+16,y,DoorComboSets[doorscreen->door_combo_set].doorcombo_u[type][1],
1636 DoorComboSets[doorscreen->door_combo_set].doorcset_u[type][1],0,0);
1637 put_combo(dest,x,y+16,DoorComboSets[doorscreen->door_combo_set].doorcombo_u[type][2],
1638 DoorComboSets[doorscreen->door_combo_set].doorcset_u[type][2],0,0);
1639 put_combo(dest,x+16,y+16,DoorComboSets[doorscreen->door_combo_set].doorcombo_u[type][3],
1640 DoorComboSets[doorscreen->door_combo_set].doorcset_u[type][3],0,0);
1641 break;
1642
1643 case down:
1644 put_combo(dest,x,y,DoorComboSets[doorscreen->door_combo_set].doorcombo_d[type][0],
1645 DoorComboSets[doorscreen->door_combo_set].doorcset_d[type][0],0,0);
1646 put_combo(dest,x+16,y,DoorComboSets[doorscreen->door_combo_set].doorcombo_d[type][1],
1647 DoorComboSets[doorscreen->door_combo_set].doorcset_d[type][1],0,0);
1648 put_combo(dest,x,y+16,DoorComboSets[doorscreen->door_combo_set].doorcombo_d[type][2],
1649 DoorComboSets[doorscreen->door_combo_set].doorcset_d[type][2],0,0);
1650 put_combo(dest,x+16,y+16,DoorComboSets[doorscreen->door_combo_set].doorcombo_d[type][3],
1651 DoorComboSets[doorscreen->door_combo_set].doorcset_d[type][3],0,0);
1652 break;
1653
1654 case left:
1655 put_combo(dest,x,y,DoorComboSets[doorscreen->door_combo_set].doorcombo_l[type][0],
1656 DoorComboSets[doorscreen->door_combo_set].doorcset_l[type][0],0,0);
1657 put_combo(dest,x,y+16,DoorComboSets[doorscreen->door_combo_set].doorcombo_l[type][2],
1658 DoorComboSets[doorscreen->door_combo_set].doorcset_l[type][2],0,0);
1659 put_combo(dest,x,y+32,DoorComboSets[doorscreen->door_combo_set].doorcombo_l[type][4],
1660 DoorComboSets[doorscreen->door_combo_set].doorcset_l[type][4],0,0);
1661
1662 if(x+16 >= dest->w)
1663 break;
1664
1665 put_combo(dest,x+16,y,DoorComboSets[doorscreen->door_combo_set].doorcombo_l[type][1],
1666 DoorComboSets[doorscreen->door_combo_set].doorcset_l[type][1],0,0);
1667 put_combo(dest,x+16,y+16,DoorComboSets[doorscreen->door_combo_set].doorcombo_l[type][3],
1668 DoorComboSets[doorscreen->door_combo_set].doorcset_l[type][3],0,0);
1669 put_combo(dest,x+16,y+32,DoorComboSets[doorscreen->door_combo_set].doorcombo_l[type][5],
1670 DoorComboSets[doorscreen->door_combo_set].doorcset_l[type][5],0,0);
1671 break;
1672
1673 case right:
1674
1675 put_combo(dest,x+16,y,DoorComboSets[doorscreen->door_combo_set].doorcombo_r[type][1],
1676 DoorComboSets[doorscreen->door_combo_set].doorcset_r[type][1],0,0);
1677 put_combo(dest,x+16,y+16,DoorComboSets[doorscreen->door_combo_set].doorcombo_r[type][3],
1678 DoorComboSets[doorscreen->door_combo_set].doorcset_r[type][3],0,0);
1679 put_combo(dest,x+16,y+32,DoorComboSets[doorscreen->door_combo_set].doorcombo_r[type][5],
1680 DoorComboSets[doorscreen->door_combo_set].doorcset_r[type][5],0,0);
1681
1682 if(x+16 <= 0)
1683 break;
1684
1685 put_combo(dest,x,y,DoorComboSets[doorscreen->door_combo_set].doorcombo_r[type][0],
1686 DoorComboSets[doorscreen->door_combo_set].doorcset_r[type][0],0,0);
1687 put_combo(dest,x,y+16,DoorComboSets[doorscreen->door_combo_set].doorcombo_r[type][2],
1688 DoorComboSets[doorscreen->door_combo_set].doorcset_r[type][2],0,0);
1689 put_combo(dest,x,y+32,DoorComboSets[doorscreen->door_combo_set].doorcombo_r[type][4],
1690 DoorComboSets[doorscreen->door_combo_set].doorcset_r[type][4],0,0);
1691 break;
1692 }
1693
1694 break;
1695
1696 case dt_pass:
1697 case dt_wall:
1698 case dt_walk:
1699 default:
1700 break;
1701 }
1702 }
1703
1704 void zmap::over_door(BITMAP *dest,int32_t pos,int32_t side,int32_t xofs,int32_t yofs,bool, int32_t scr)
1705 {
1706 int32_t x=((pos&15)<<4)+xofs;
1707 int32_t y=(pos&0xF0)+yofs;
1708 mapscr *doorscreen=(prv_mode?get_prvscr():screens+scr);
1709
1710
1711 switch(side)
1712 {
1713 case up:
1714 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_u[0]!=0)
1715 {
1716 overcombo(dest,x,y,
1717 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_u[0],
1718 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_u[0]);
1719 }
1720
1721 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_u[1]!=0)
1722 {
1723 overcombo(dest,x+16,y,
1724 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_u[1],
1725
1726 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_u[1]);
1727 }
1728
1729 break;
1730
1731 case down:
1732 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_d[0]!=0)
1733 {
1734 overcombo(dest,x,y,
1735 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_d[0],
1736 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_d[0]);
1737 }
1738
1739 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_d[1]!=0)
1740 {
1741 overcombo(dest,x+16,y,
1742 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_d[1],
1743 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_d[1]);
1744 }
1745
1746 break;
1747
1748 case left:
1749 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_l[0]!=0)
1750 {
1751 overcombo(dest,x,y,
1752 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_l[0],
1753 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_l[0]);
1754 }
1755
1756 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_l[1]!=0)
1757 {
1758 overcombo(dest,x,y+16,
1759 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_l[1],
1760 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_l[1]);
1761 }
1762
1763 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_l[2]!=0)
1764 {
1765 overcombo(dest,x,y+32,
1766 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_l[2],
1767 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_l[2]);
1768 }
1769
1770 break;
1771
1772 case right:
1773 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_r[0]!=0)
1774 {
1775 overcombo(dest,x,y,
1776 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_r[0],
1777 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_r[0]);
1778 }
1779
1780 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_r[1]!=0)
1781 {
1782 overcombo(dest,x,y+16,
1783
1784 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_r[1],
1785 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_r[1]);
1786 }
1787
1788 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_r[2]!=0)
1789 {
1790 overcombo(dest,x,y+32,
1791 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_r[2],
1792 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_r[2]);
1793 }
1794
1795 break;
1796 }
1797 }
1798
1799 bool zmap::misaligned(int32_t map, int32_t screen, int32_t i, int32_t dir)
1800 {
1801 word cmbcheck1, cmbcheck2;
1802 newcombo combocheck1, combocheck2;
1803 combocheck1 = combobuf[0];
1804 combocheck2 = combobuf[0];
1805 combocheck1.walk = 0;
1806 combocheck2.walk = 0;
1807
1808 int32_t layermap, layerscreen;
1809
1810 switch(dir)
1811 {
1812 case up:
1813 {
1814 if(i>15) //not top row of combos
1815 {
1816 return false;
1817 }
1818
1819 if(screen<16) //top row of screens
1820 {
1821 return false;
1822
1823 }
1824
1825 //check main screen
1826 cmbcheck1 = vbound(AbsoluteScr(map, screen)->data[i], 0, MAXCOMBOS-1);
1827 cmbcheck2 = vbound(AbsoluteScr(map, screen-16)->data[i+160], 0, MAXCOMBOS-1);
1828 if (combobuf[cmbcheck1].type != cBRIDGE || !get_qr(qr_OLD_BRIDGE_COMBOS)) combocheck1.walk|=combobuf[cmbcheck1].walk;
1829 if (combobuf[cmbcheck2].type != cBRIDGE || !get_qr(qr_OLD_BRIDGE_COMBOS)) combocheck2.walk|=combobuf[cmbcheck2].walk;
1830
1831 //check layer 1
1832 layermap=AbsoluteScr(map, screen)->layermap[0]-1;
1833
1834 if(layermap>-1 && layermap<map_count)
1835 {
1836 layerscreen=AbsoluteScr(map, screen)->layerscreen[0];
1837 cmbcheck1 = AbsoluteScr(layermap, layerscreen)->data[i];
1838 if (combobuf[cmbcheck1].type == cBRIDGE)
1839 {
1840 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1841 {
1842 int efflag = (combobuf[cmbcheck1].walk & 0xF0)>>4;
1843 int newsolid = (combobuf[cmbcheck1].walk & 0xF);
1844 combocheck1.walk = ((newsolid | combocheck1.walk) & (~efflag)) | (newsolid & efflag);
1845 }
1846 else combocheck1.walk&=combobuf[cmbcheck1].walk;
1847 }
1848 else combocheck1.walk|=combobuf[cmbcheck1].walk;
1849 }
1850
1851 layermap=AbsoluteScr(map, screen-16)->layermap[0]-1;
1852
1853 if(layermap>-1 && layermap<map_count)
1854 {
1855 layerscreen=AbsoluteScr(map, screen-16)->layerscreen[0];
1856 cmbcheck2 = AbsoluteScr(layermap, layerscreen)->data[i+160];
1857 if (combobuf[cmbcheck2].type == cBRIDGE)
1858 {
1859 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1860 {
1861 int efflag = (combobuf[cmbcheck2].walk & 0xF0)>>4;
1862 int newsolid = (combobuf[cmbcheck2].walk & 0xF);
1863 combocheck2.walk = ((newsolid | combocheck2.walk) & (~efflag)) | (newsolid & efflag);
1864 }
1865 else combocheck2.walk&=combobuf[cmbcheck2].walk;
1866 }
1867 else combocheck2.walk|=combobuf[cmbcheck2].walk;
1868 }
1869
1870 //check layer 2
1871 layermap=AbsoluteScr(map, screen)->layermap[1]-1;
1872
1873 if(layermap>-1 && layermap<map_count)
1874 {
1875 layerscreen=AbsoluteScr(map, screen)->layerscreen[1];
1876
1877 cmbcheck1 = AbsoluteScr(layermap, layerscreen)->data[i];
1878 if (combobuf[cmbcheck2].type == cBRIDGE)
1879 {
1880 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1881 {
1882 int efflag = (combobuf[cmbcheck1].walk & 0xF0)>>4;
1883 int newsolid = (combobuf[cmbcheck1].walk & 0xF);
1884 combocheck1.walk = ((newsolid | combocheck1.walk) & (~efflag)) | (newsolid & efflag);
1885 }
1886 else combocheck1.walk&=combobuf[cmbcheck1].walk;
1887 }
1888 else combocheck1.walk|=combobuf[cmbcheck1].walk;
1889 }
1890
1891 layermap=AbsoluteScr(map, screen-16)->layermap[1]-1;
1892
1893 if(layermap>-1 && layermap<map_count)
1894 {
1895 layerscreen=AbsoluteScr(map, screen-16)->layerscreen[1];
1896 cmbcheck2 = AbsoluteScr(layermap, layerscreen)->data[i+160];
1897 if (combobuf[cmbcheck2].type == cBRIDGE)
1898 {
1899 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1900 {
1901 int efflag = (combobuf[cmbcheck2].walk & 0xF0)>>4;
1902 int newsolid = (combobuf[cmbcheck2].walk & 0xF);
1903 combocheck2.walk = ((newsolid | combocheck2.walk) & (~efflag)) | (newsolid & efflag);
1904 }
1905 else combocheck2.walk&=combobuf[cmbcheck2].walk;
1906 }
1907 else combocheck2.walk|=combobuf[cmbcheck2].walk;
1908 }
1909
1910 if(((combocheck1.walk&5)*2)!=(combocheck2.walk&10))
1911 {
1912 return true;
1913 }
1914
1915 break;
1916 }
1917 case down:
1918 {
1919 if(i<160) //not bottom row of combos
1920 {
1921 return false;
1922 }
1923
1924 if(screen>111) //bottom row of screens
1925 {
1926 return false;
1927 }
1928
1929 //check main screen
1930 cmbcheck1 = vbound(AbsoluteScr(map, screen)->data[i], 0, MAXCOMBOS-1);
1931 cmbcheck2 = vbound(AbsoluteScr(map, screen+16)->data[i-160], 0, MAXCOMBOS-1);
1932 if (combobuf[cmbcheck1].type != cBRIDGE || !get_qr(qr_OLD_BRIDGE_COMBOS)) combocheck1.walk|=combobuf[cmbcheck1].walk;
1933 if (combobuf[cmbcheck2].type != cBRIDGE || !get_qr(qr_OLD_BRIDGE_COMBOS)) combocheck2.walk|=combobuf[cmbcheck2].walk;
1934
1935
1936 //check layer 1
1937 layermap=AbsoluteScr(map, screen)->layermap[0]-1;
1938
1939 if(layermap>-1 && layermap<map_count)
1940 {
1941 layerscreen=AbsoluteScr(map, screen)->layerscreen[0];
1942 cmbcheck1 = AbsoluteScr(layermap, layerscreen)->data[i];
1943 if (combobuf[cmbcheck1].type == cBRIDGE)
1944 {
1945 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1946 {
1947 int efflag = (combobuf[cmbcheck1].walk & 0xF0)>>4;
1948 int newsolid = (combobuf[cmbcheck1].walk & 0xF);
1949 combocheck1.walk = ((newsolid | combocheck1.walk) & (~efflag)) | (newsolid & efflag);
1950 }
1951 else combocheck1.walk&=combobuf[cmbcheck1].walk;
1952 }
1953 else combocheck1.walk|=combobuf[cmbcheck1].walk;
1954 }
1955
1956 layermap=AbsoluteScr(map, screen+16)->layermap[0]-1;
1957
1958 if(layermap>-1 && layermap<map_count)
1959 {
1960 layerscreen=AbsoluteScr(map, screen+16)->layerscreen[0];
1961 cmbcheck2 = AbsoluteScr(layermap, layerscreen)->data[i-160];
1962 if (combobuf[cmbcheck2].type == cBRIDGE)
1963 {
1964 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1965 {
1966 int efflag = (combobuf[cmbcheck2].walk & 0xF0)>>4;
1967 int newsolid = (combobuf[cmbcheck2].walk & 0xF);
1968 combocheck2.walk = ((newsolid | combocheck2.walk) & (~efflag)) | (newsolid & efflag);
1969 }
1970 else combocheck2.walk&=combobuf[cmbcheck2].walk;
1971 }
1972 else combocheck2.walk|=combobuf[cmbcheck2].walk;
1973 }
1974
1975 //check layer 2
1976 layermap=AbsoluteScr(map, screen)->layermap[1]-1;
1977
1978 if(layermap>-1 && layermap<map_count)
1979 {
1980 layerscreen=AbsoluteScr(map, screen)->layerscreen[1];
1981 cmbcheck1 = AbsoluteScr(layermap, layerscreen)->data[i];
1982 if (combobuf[cmbcheck1].type == cBRIDGE)
1983 {
1984 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1985 {
1986 int efflag = (combobuf[cmbcheck1].walk & 0xF0)>>4;
1987 int newsolid = (combobuf[cmbcheck1].walk & 0xF);
1988 combocheck1.walk = ((newsolid | combocheck1.walk) & (~efflag)) | (newsolid & efflag);
1989 }
1990 else combocheck1.walk&=combobuf[cmbcheck1].walk;
1991 }
1992 else combocheck1.walk|=combobuf[cmbcheck1].walk;
1993 }
1994
1995 layermap=AbsoluteScr(map, screen+16)->layermap[1]-1;
1996
1997 if(layermap>-1 && layermap<map_count)
1998 {
1999 layerscreen=AbsoluteScr(map, screen+16)->layerscreen[1];
2000 cmbcheck2 = AbsoluteScr(layermap, layerscreen)->data[i-160];
2001 if (combobuf[cmbcheck2].type == cBRIDGE)
2002 {
2003 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
2004 {
2005 int efflag = (combobuf[cmbcheck2].walk & 0xF0)>>4;
2006 int newsolid = (combobuf[cmbcheck2].walk & 0xF);
2007 combocheck2.walk = ((newsolid | combocheck2.walk) & (~efflag)) | (newsolid & efflag);
2008 }
2009 else combocheck2.walk&=combobuf[cmbcheck2].walk;
2010 }
2011 else combocheck2.walk|=combobuf[cmbcheck2].walk;
2012 }
2013
2014 if((combocheck1.walk&10)!=((combocheck2.walk&5)*2))
2015 {
2016 return true;
2017 }
2018
2019 break;
2020 }
2021 case left:
2022 {
2023 if((i&0xF)!=0) //not left column of combos
2024 {
2025 return false;
2026 }
2027
2028 if((screen&0xF)==0) //left column of screens
2029 {
2030 return false;
2031 }
2032
2033 //check main screen
2034 cmbcheck1 = AbsoluteScr(map, screen)->data[i];
2035 cmbcheck2 = AbsoluteScr(map, screen-1)->data[i+15];
2036 if (combobuf[cmbcheck1].type != cBRIDGE || !get_qr(qr_OLD_BRIDGE_COMBOS)) combocheck1.walk|=combobuf[cmbcheck1].walk;
2037 if (combobuf[cmbcheck2].type != cBRIDGE || !get_qr(qr_OLD_BRIDGE_COMBOS)) combocheck2.walk|=combobuf[cmbcheck2].walk;
2038
2039 //check layer 1
2040 layermap=AbsoluteScr(map, screen)->layermap[0]-1;
2041
2042 if(layermap>-1 && layermap<map_count)
2043 {
2044 layerscreen=AbsoluteScr(map, screen)->layerscreen[0];
2045 cmbcheck1 = AbsoluteScr(layermap, layerscreen)->data[i];
2046 if (combobuf[cmbcheck1].type == cBRIDGE)
2047 {
2048 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
2049 {
2050 int efflag = (combobuf[cmbcheck1].walk & 0xF0)>>4;
2051 int newsolid = (combobuf[cmbcheck1].walk & 0xF);
2052 combocheck1.walk = ((newsolid | combocheck1.walk) & (~efflag)) | (newsolid & efflag);
2053 }
2054 else combocheck1.walk&=combobuf[cmbcheck1].walk;
2055 }
2056 else combocheck1.walk|=combobuf[cmbcheck1].walk;
2057 }
2058
2059 layermap=AbsoluteScr(map, screen-1)->layermap[0]-1;
2060
2061 if(layermap>-1 && layermap<map_count)
2062 {
2063 layerscreen=AbsoluteScr(map, screen-1)->layerscreen[0];
2064 cmbcheck2 = AbsoluteScr(layermap, layerscreen)->data[i+15];
2065 if (combobuf[cmbcheck2].type == cBRIDGE)
2066 {
2067 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
2068 {
2069 int efflag = (combobuf[cmbcheck2].walk & 0xF0)>>4;
2070 int newsolid = (combobuf[cmbcheck2].walk & 0xF);
2071 combocheck2.walk = ((newsolid | combocheck2.walk) & (~efflag)) | (newsolid & efflag);
2072 }
2073 else combocheck2.walk&=combobuf[cmbcheck2].walk;
2074 }
2075 else combocheck2.walk|=combobuf[cmbcheck2].walk;
2076 }
2077
2078 //check layer 2
2079 layermap=AbsoluteScr(map, screen)->layermap[1]-1;
2080
2081 if(layermap>-1 && layermap<map_count)
2082 {
2083 layerscreen=AbsoluteScr(map, screen)->layerscreen[1];
2084 cmbcheck1 = AbsoluteScr(layermap, layerscreen)->data[i];
2085 if (combobuf[cmbcheck1].type == cBRIDGE)
2086 {
2087 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
2088 {
2089 int efflag = (combobuf[cmbcheck1].walk & 0xF0)>>4;
2090 int newsolid = (combobuf[cmbcheck1].walk & 0xF);
2091 combocheck1.walk = ((newsolid | combocheck1.walk) & (~efflag)) | (newsolid & efflag);
2092 }
2093 else combocheck1.walk&=combobuf[cmbcheck1].walk;
2094 }
2095 else combocheck1.walk|=combobuf[cmbcheck1].walk;
2096 }
2097
2098 layermap=AbsoluteScr(map, screen-1)->layermap[1]-1;
2099
2100 if(layermap>-1 && layermap<map_count)
2101 {
2102 layerscreen=AbsoluteScr(map, screen-1)->layerscreen[1];
2103 cmbcheck2 = AbsoluteScr(layermap, layerscreen)->data[i+15];
2104 if (combobuf[cmbcheck2].type == cBRIDGE)
2105 {
2106 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
2107 {
2108 int efflag = (combobuf[cmbcheck2].walk & 0xF0)>>4;
2109 int newsolid = (combobuf[cmbcheck2].walk & 0xF);
2110 combocheck2.walk = ((newsolid | combocheck2.walk) & (~efflag)) | (newsolid & efflag);
2111 }
2112 else combocheck2.walk&=combobuf[cmbcheck2].walk;
2113 }
2114 else combocheck2.walk|=combobuf[cmbcheck2].walk;
2115 }
2116
2117 if(((combocheck1.walk&3)*4)!=(combocheck2.walk&12))
2118 {
2119 return true;
2120 }
2121
2122 break;
2123 }
2124 case right:
2125 {
2126 if((i&0xF)!=15) //not right column of combos
2127 {
2128 return false;
2129 }
2130
2131 if((screen&0xF)==15) //right column of screens
2132 {
2133 return false;
2134 }
2135
2136 //check main screen
2137 cmbcheck1 = AbsoluteScr(map, screen)->data[i];
2138 cmbcheck2 = AbsoluteScr(map, screen+1)->data[i-15];
2139 if (combobuf[cmbcheck1].type != cBRIDGE || !get_qr(qr_OLD_BRIDGE_COMBOS)) combocheck1.walk|=combobuf[cmbcheck1].walk;
2140 if (combobuf[cmbcheck2].type != cBRIDGE || !get_qr(qr_OLD_BRIDGE_COMBOS)) combocheck2.walk|=combobuf[cmbcheck2].walk;
2141
2142 //check layer 1
2143 layermap=AbsoluteScr(map, screen)->layermap[0]-1;
2144
2145 if(layermap>-1 && layermap<map_count)
2146 {
2147 layerscreen=AbsoluteScr(map, screen)->layerscreen[0];
2148 cmbcheck1 = AbsoluteScr(layermap, layerscreen)->data[i];
2149 if (combobuf[cmbcheck1].type == cBRIDGE)
2150 {
2151 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
2152 {
2153 int efflag = (combobuf[cmbcheck1].walk & 0xF0)>>4;
2154 int newsolid = (combobuf[cmbcheck1].walk & 0xF);
2155 combocheck1.walk = ((newsolid | combocheck1.walk) & (~efflag)) | (newsolid & efflag);
2156 }
2157 else combocheck1.walk&=combobuf[cmbcheck1].walk;
2158 }
2159 else combocheck1.walk|=combobuf[cmbcheck1].walk;
2160 }
2161
2162 layermap=AbsoluteScr(map, screen+1)->layermap[0]-1;
2163
2164 if(layermap>-1 && layermap<map_count)
2165 {
2166 layerscreen=AbsoluteScr(map, screen+1)->layerscreen[0];
2167 cmbcheck2 = AbsoluteScr(layermap, layerscreen)->data[i-15];
2168 if (combobuf[cmbcheck2].type == cBRIDGE)
2169 {
2170 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
2171 {
2172 int efflag = (combobuf[cmbcheck2].walk & 0xF0)>>4;
2173 int newsolid = (combobuf[cmbcheck2].walk & 0xF);
2174 combocheck2.walk = ((newsolid | combocheck2.walk) & (~efflag)) | (newsolid & efflag);
2175 }
2176 else combocheck2.walk&=combobuf[cmbcheck2].walk;
2177 }
2178 else combocheck2.walk|=combobuf[cmbcheck2].walk;
2179 }
2180
2181 //check layer 2
2182 layermap=AbsoluteScr(map, screen)->layermap[1]-1;
2183
2184 if(layermap>-1 && layermap<map_count)
2185 {
2186 layerscreen=AbsoluteScr(map, screen)->layerscreen[1];
2187 cmbcheck1 = AbsoluteScr(layermap, layerscreen)->data[i];
2188 if (combobuf[cmbcheck1].type == cBRIDGE)
2189 {
2190 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
2191 {
2192 int efflag = (combobuf[cmbcheck1].walk & 0xF0)>>4;
2193 int newsolid = (combobuf[cmbcheck1].walk & 0xF);
2194 combocheck1.walk = ((newsolid | combocheck1.walk) & (~efflag)) | (newsolid & efflag);
2195 }
2196 else combocheck1.walk&=combobuf[cmbcheck1].walk;
2197 }
2198 else combocheck1.walk|=combobuf[cmbcheck1].walk;
2199 }
2200
2201 layermap=AbsoluteScr(map, screen+1)->layermap[1]-1;
2202
2203 if(layermap>-1 && layermap<map_count)
2204 {
2205 layerscreen=AbsoluteScr(map, screen+1)->layerscreen[1];
2206
2207 cmbcheck2 = AbsoluteScr(layermap, layerscreen)->data[i-15];
2208 if (combobuf[cmbcheck2].type == cBRIDGE)
2209 {
2210 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
2211 {
2212 int efflag = (combobuf[cmbcheck2].walk & 0xF0)>>4;
2213 int newsolid = (combobuf[cmbcheck2].walk & 0xF);
2214 combocheck2.walk = ((newsolid | combocheck2.walk) & (~efflag)) | (newsolid & efflag);
2215 }
2216 else combocheck2.walk&=combobuf[cmbcheck2].walk;
2217 }
2218 else combocheck2.walk|=combobuf[cmbcheck2].walk;
2219 }
2220
2221 if((combocheck1.walk&12)!=((combocheck2.walk&3)*4))
2222 {
2223 return true;
2224 }
2225
2226 break;
2227 }
2228 }
2229
2230 return false;
2231 }
2232
2233 void zmap::check_alignments(BITMAP* dest,int32_t x,int32_t y,int32_t scr)
2234 {
2235 int32_t checkcombo;
2236
2237 if(alignment_arrow_timer>31)
2238 {
2239 if(scr<0)
2240 {
2241 scr=cursor.screen;
2242 }
2243
2244 if((scr<128)) //do the misalignment arrows
2245 {
2246 for(checkcombo=1; checkcombo<15; checkcombo++) //check the top row (except the corners)
2247 {
2248 if(misaligned(cursor.map, scr, checkcombo, up))
2249 {
2250 masked_blit(arrow_bmp[0],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2251 }
2252 }
2253
2254 for(checkcombo=161; checkcombo<175; checkcombo++) //check the top row (except the corners)
2255 {
2256 if(misaligned(cursor.map, scr, checkcombo, down))
2257 {
2258 masked_blit(arrow_bmp[1],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2259 }
2260 }
2261
2262 for(checkcombo=16; checkcombo<160; checkcombo+=16) //check the left side (except the corners)
2263 {
2264 if(misaligned(cursor.map, scr, checkcombo, left))
2265 {
2266 masked_blit(arrow_bmp[2],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2267 }
2268 }
2269
2270 for(checkcombo=31; checkcombo<175; checkcombo+=16) //check the right side (except the corners)
2271 {
2272 if(misaligned(cursor.map, scr, checkcombo, right))
2273 {
2274 masked_blit(arrow_bmp[3],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2275 }
2276 }
2277
2278 int32_t tempalign;
2279
2280 //check top left corner
2281 checkcombo=0;
2282 tempalign=0;
2283 tempalign+=(misaligned(cursor.map, scr, checkcombo, up))?1:0;
2284 tempalign+=(misaligned(cursor.map, scr, checkcombo, left))?2:0;
2285
2286 switch(tempalign)
2287 {
2288 case 0:
2289 break;
2290
2291 case 1: //up
2292 masked_blit(arrow_bmp[0],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2293 break;
2294
2295 case 2: //left
2296 masked_blit(arrow_bmp[2],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2297 break;
2298
2299 case 3: //up-left
2300 masked_blit(arrow_bmp[4],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2301 break;
2302 }
2303
2304 //check top right corner
2305 checkcombo=15;
2306 tempalign=0;
2307 tempalign+=(misaligned(cursor.map, scr, checkcombo, up))?1:0;
2308 tempalign+=(misaligned(cursor.map, scr, checkcombo, right))?2:0;
2309
2310 switch(tempalign)
2311 {
2312 case 0:
2313 break;
2314
2315 case 1: //up
2316 masked_blit(arrow_bmp[0],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2317 break;
2318
2319 case 2: //right
2320 masked_blit(arrow_bmp[3],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2321 break;
2322
2323 case 3: //up-right
2324 masked_blit(arrow_bmp[5],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2325 break;
2326 }
2327
2328 //check bottom left corner
2329 checkcombo=160;
2330 tempalign=0;
2331 tempalign+=(misaligned(cursor.map, scr, checkcombo, down))?1:0;
2332 tempalign+=(misaligned(cursor.map, scr, checkcombo, left))?2:0;
2333
2334 switch(tempalign)
2335 {
2336 case 0:
2337 break;
2338
2339 case 1: //down
2340 masked_blit(arrow_bmp[1],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2341 break;
2342
2343 case 2: //left
2344 masked_blit(arrow_bmp[2],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2345 break;
2346
2347 case 3: //down-left
2348 masked_blit(arrow_bmp[6],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2349 break;
2350 }
2351
2352 //check bottom right corner
2353
2354 checkcombo=175;
2355 tempalign=0;
2356 tempalign+=(misaligned(cursor.map, scr, checkcombo, down))?1:0;
2357 tempalign+=(misaligned(cursor.map, scr, checkcombo, right))?2:0;
2358
2359 switch(tempalign)
2360 {
2361 case 0:
2362 break;
2363
2364 case 1: //down
2365 masked_blit(arrow_bmp[1],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2366 break;
2367
2368 case 2: //right
2369 masked_blit(arrow_bmp[3],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2370 break;
2371
2372 case 3: //down-right
2373 masked_blit(arrow_bmp[7],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2374 break;
2375 }
2376 }
2377 }
2378 }
2379
2380 int32_t zmap::MAPCOMBO3(int32_t map, int32_t screen, int32_t layer, int32_t x,int32_t y)
2381 {
2382 return MAPCOMBO3(map, screen, layer, COMBOPOS(x,y));
2383 }
2384
2385 int32_t zmap::MAPCOMBO3(int32_t map, int32_t screen, int32_t layer, int32_t pos)
2386 {
2387 if (map < 0 || screen < 0) return 0;
2388
2389 if(pos>175 || pos < 0)
2390 return 0;
2391
2392 mapscr const* m = &TheMaps[(map*MAPSCRS)+screen];
2393
2394 if (!m->is_valid()) return 0;
2395
2396 int32_t mapid = (layer < 0 ? -1 : ((m->layermap[layer] - 1) * MAPSCRS + m->layerscreen[layer]));
2397
2398 if (layer >= 0 && (mapid < 0 || mapid > MAXMAPS*MAPSCRS)) return 0;
2399
2400 mapscr const* scr = ((mapid < 0 || mapid > MAXMAPS*MAPSCRS) ? m : &TheMaps[mapid]);
2401
2402 if (!scr->is_valid()) return 0;
2403
2404 return scr->data[pos]; // entire combo code
2405 }
2406
2407 // Takes array index layer num., not actual layer num.
2408 int32_t zmap::MAPCOMBO2(int32_t lyr,int32_t x,int32_t y, int32_t map, int32_t scr)
2409 {
2410 if(lyr<=-1) return MAPCOMBO(x,y,map,scr);
2411
2412 if(map<0)
2413 map=cursor.map;
2414
2415 if(scr<0)
2416 scr=cursor.screen;
2417
2418 mapscr *screen1;
2419
2420 if(prv_mode)
2421 {
2422 screen1=get_prvscr();
2423 }
2424 else
2425 {
2426 screen1=AbsoluteScr(cursor.map,cursor.screen);
2427 }
2428
2429 int32_t layermap;
2430 layermap=screen1->layermap[lyr]-1;
2431
2432 if(layermap<0 || layermap >= map_count) return 0;
2433
2434 mapscr *layer;
2435
2436 if(prv_mode)
2437 layer = &prvlayers[lyr];
2438 else
2439 layer = AbsoluteScr(layermap,screen1->layerscreen[lyr]);
2440
2441 int32_t pos = COMBOPOS(x,y);
2442
2443 if(pos>175 || pos < 0)
2444 return 0;
2445
2446 return layer->data[pos];
2447 }
2448
2449 int32_t zmap::MAPCOMBO(int32_t x,int32_t y, int32_t map, int32_t scr) //map=-1,scr=-1
2450 {
2451 if(map<0)
2452 map=cursor.map;
2453
2454 if(scr<0)
2455 scr=cursor.screen;
2456
2457 mapscr *screen1;
2458
2459 if(prv_mode)
2460 {
2461 screen1=get_prvscr();
2462 }
2463 else
2464 {
2465 screen1=AbsoluteScr(cursor.map,cursor.screen);
2466 }
2467
2468 x = vbound(x, 0, 16*16);
2469 y = vbound(y, 0, 11*16);
2470 int32_t combo = COMBOPOS(x,y);
2471
2472 if(combo>175 || combo < 0)
2473 return 0;
2474
2475 return screen1->data[combo];
2476 }
2477
2478 int32_t zmap::MAPFLAG3(int32_t map, int32_t screen, int32_t layer, int32_t x,int32_t y)
2479 {
2480 return MAPFLAG3(map, screen, layer, COMBOPOS(x,y));
2481 }
2482
2483 int32_t zmap::MAPFLAG3(int32_t map, int32_t screen, int32_t layer, int32_t pos)
2484 {
2485 if (map < 0 || screen < 0) return 0;
2486
2487 if(pos>175 || pos < 0)
2488 return 0;
2489
2490 mapscr const* m = &TheMaps[(map*MAPSCRS)+screen];
2491
2492 if (!m->is_valid()) return 0;
2493
2494 int32_t mapid = (layer < 0 ? -1 : ((m->layermap[layer] - 1) * MAPSCRS + m->layerscreen[layer]));
2495
2496 if (layer >= 0 && (mapid < 0 || mapid > MAXMAPS*MAPSCRS)) return 0;
2497
2498 mapscr const* scr = ((mapid < 0 || mapid > MAXMAPS*MAPSCRS) ? m : &TheMaps[mapid]);
2499
2500 if (!scr->is_valid()) return 0;
2501
2502 return scr->sflag[pos]; // entire combo code
2503 }
2504
2505 int32_t zmap::MAPFLAG2(int32_t lyr,int32_t x,int32_t y, int32_t map, int32_t scr)
2506 {
2507 if(lyr<=-1) return MAPFLAG(x,y,map,scr);
2508
2509 if(map<0)
2510 map=cursor.map;
2511
2512 if(scr<0)
2513 scr=cursor.screen;
2514
2515 mapscr *screen1;
2516
2517 if(prv_mode)
2518 {
2519 screen1=get_prvscr();
2520 }
2521 else
2522 {
2523 screen1=AbsoluteScr(cursor.map,cursor.screen);
2524 }
2525
2526 int32_t layermap;
2527 layermap=screen1->layermap[lyr]-1;
2528
2529 if(layermap<0 || layermap >= map_count) return 0;
2530
2531 mapscr *layer;
2532
2533 if(prv_mode)
2534 layer = &prvlayers[lyr];
2535 else
2536 layer = AbsoluteScr(layermap,screen1->layerscreen[lyr]);
2537
2538 int32_t combo = COMBOPOS(x,y);
2539
2540 if(combo>175 || combo < 0)
2541 return 0;
2542
2543 return layer->sflag[combo];
2544 }
2545
2546 int32_t zmap::MAPFLAG(int32_t x,int32_t y, int32_t map, int32_t scr) //map=-1,scr=-1
2547 {
2548 if(map<0)
2549 map=cursor.map;
2550
2551 if(scr<0)
2552 scr=cursor.screen;
2553
2554 mapscr *screen1;
2555
2556 if(prv_mode)
2557 {
2558 screen1=get_prvscr();
2559 }
2560 else
2561 {
2562 screen1=AbsoluteScr(cursor.map,cursor.screen);
2563 }
2564
2565 x = vbound(x, 0, 16*16);
2566 y = vbound(y, 0, 11*16);
2567 int32_t combo = COMBOPOS(x,y);
2568
2569 if(combo>175 || combo < 0)
2570 return 0;
2571
2572 return screen1->sflag[combo];
2573 }
2574
2575 void zmap::draw_darkness(BITMAP* dest, BITMAP* transdest)
2576 {
2577 mapscr *layers[7];
2578 mapscr *basescr;
2579 if(prv_mode)
2580 {
2581 layers[0] = &prvscr;
2582 basescr = layers[0];
2583 for(auto q = 1; q < 7; ++q)
2584 {
2585 if(prvlayers[q-1].valid)
2586 layers[q] = &(prvlayers[q-1]);
2587 else layers[q] = NULL;
2588 }
2589 }
2590 else
2591 {
2592 layers[0] = AbsoluteScr(cursor.map, cursor.screen);
2593 basescr = layers[0];
2594 for(auto q = 1; q < 7; ++q)
2595 {
2596 int32_t lmap = basescr->layermap[q-1]-1;
2597 int32_t lscr = basescr->layerscreen[q-1];
2598 if(lmap < 0)
2599 layers[q] = NULL;
2600 else layers[q] = AbsoluteScr(lmap, lscr);
2601 }
2602 }
2603 for(auto q = 0; q < 7; ++q)
2604 {
2605 if(!layers[q]) continue;
2606 for(auto pos = 0; pos < 176; ++pos)
2607 {
2608 newcombo const& cmb = combobuf[layers[q]->data[pos]];
2609 if(cmb.type == cTORCH)
2610 do_torch_combo(cmb, COMBOX(pos)+8, COMBOY(pos)+8, dest, transdest);
2611 }
2612 }
2613 word maxffc = basescr->numFFC();
2614 for(auto q = 0; q < maxffc; ++q)
2615 {
2616 newcombo const& cmb = combobuf[basescr->ffcs[q].data];
2617 if(cmb.type == cTORCH)
2618 do_torch_combo(cmb, (basescr->ffcs[q].x.getInt())+(basescr->ffEffectWidth(q)/2), (basescr->ffcs[q].y.getInt())+(basescr->ffEffectHeight(q)/2), dest, transdest);
2619 }
2620 }
2621
2622 void drawcombo(BITMAP* dest, int32_t x, int32_t y, int32_t cid, int32_t cset, int32_t flags,
2623 int32_t sflag, bool over = true, bool transp = false, bool dither = false)
2624 {
2625 newcombo const& cmb = combobuf[cid];
2626 if(cmb.animflags & AF_TRANSPARENT) transp = !transp;
2627 if(dither)
2628 {
2629 if (LayerDitherSz == 0)
2630 return;
2631 BITMAP* buf = create_bitmap_ex(8,16,16);
2632 clear_bitmap(buf);
2633 overcombo(buf,0,0,cid,cset);
2634 ditherblit(buf,nullptr,0,dithChecker,LayerDitherSz,x,y);
2635 if(over)
2636 {
2637 if(transp)
2638 {
2639 color_map = trans_table2;
2640 draw_trans_sprite(dest, buf, x, y);
2641 color_map = trans_table;
2642 }
2643 else masked_blit(buf, dest, 0, 0, x, y, 16, 16);
2644 }
2645 else masked_blit(buf, dest, 0, 0, x, y, 16, 16);
2646 destroy_bitmap(buf);
2647 }
2648 else if(over)
2649 {
2650 if(transp)
2651 overcombotranslucent(dest,x,y,cid,cset,0);
2652 else overcombo(dest,x,y,cid,cset);
2653 }
2654 else put_combo(dest,x,y,cid,cset,flags,sflag);
2655 }
2656 static void _zmap_drawlayer(BITMAP* dest, int32_t x, int32_t y, mapscr* md, int32_t flags, bool trans, bool over, bool dither, bool passflag = false)
2657 {
2658 if(!md) return;
2659 for (int32_t i = 0; i < 176; i++)
2660 drawcombo(dest, ((i&15)<<4)+x, (i&0xF0)+y, md->data[i], md->cset[i], flags, passflag ? md->sflag[i] : 0, over, trans, dither);
2661 }
2662 static void _zmap_drawlayer_ohead(BITMAP* dest, int32_t x, int32_t y, mapscr* md, int32_t flags, bool trans, bool dither)
2663 {
2664 if(!md) return;
2665 for (int32_t i = 0; i < 176; i++)
2666 {
2667 int data = md->data[i];
2668 if(combo_class_buf[combobuf[data].type].overhead)
2669 drawcombo(dest, ((i&15)<<4)+x, (i&0xF0)+y, data, md->cset[i], 0, 0, true, trans, dither);
2670 }
2671 }
2672 static mapscr* _zmap_get_lyr_checked(int lyr, mapscr* basescr)
2673 {
2674 if(!LayerMaskInt[lyr])
2675 return nullptr;
2676 if(lyr == 0)
2677 return basescr;
2678 int layermap = basescr->layermap[lyr-1]-1;
2679
2680 if(layermap>-1 && layermap<map_count)
2681 {
2682 int layerscreen = layermap*MAPSCRS+basescr->layerscreen[lyr-1];
2683 return &TheMaps[layerscreen];
2684 }
2685 return nullptr;
2686 }
2687 static void _zmap_draw_ffc_layer(BITMAP* dest,int32_t x,int32_t y,int32_t flags,mapscr* basescr, int32_t layer)
2688 {
2689 int num_ffcs = basescr->numFFC();
2690 for(int32_t i=num_ffcs-1; i>=0; i--)
2691 {
2692 auto const& ff = basescr->ffcs[i];
2693 if(ff.data)
2694 {
2695 if(!(ff.flags&ffc_changer))
2696 {
2697 int32_t tx=(ff.x.getInt())+x;
2698 int32_t ty=(ff.y.getInt())+y;
2699
2700 if((ff.flags&ffc_overlay) ? layer == -1 : layer == ff.layer)
2701 {
2702 if(ff.flags&ffc_trans)
2703 overcomboblocktranslucent(dest,tx,ty,ff.data, ff.cset, ff.txsz, ff.tysz,128);
2704 else
2705 overcomboblock(dest, tx, ty, ff.data, ff.cset, ff.txsz, ff.tysz);
2706 }
2707 }
2708 }
2709 }
2710 }
2711 void zmap::draw(BITMAP* dest,int32_t x,int32_t y,int32_t flags,int32_t map,int32_t screen,int32_t hl_layer)
2712 {
2713 #define HL_LAYER(lyr) (!(NoHighlightLayer0 && hl_layer == 0) && hl_layer > -1 && hl_layer != lyr)
2714 int32_t antiflags=(flags&~cFLAGS)&~cWALK;
2715 bool olddraw = get_qr(qr_CLASSIC_DRAWING_ORDER);
2716
2717 if(map<0)
2718 map=cursor.map;
2719
2720 if(screen<0)
2721 screen=cursor.screen;
2722
2723 mapscr *basescr;
2724 mapscr* layers[7] = {nullptr};
2725
2726 if(prv_mode)
2727 {
2728 hl_layer = -1;
2729 basescr=get_prvscr();
2730 }
2731 else
2732 {
2733 basescr=AbsoluteScr(map,screen);
2734 }
2735 layers[0] = _zmap_get_lyr_checked(0,basescr);
2736 for(int lyr = 1; lyr < 7; ++lyr)
2737 {
2738 layers[lyr] = prv_mode ? ((&prvlayers[lyr-1])->valid ? &prvlayers[lyr - 1] : nullptr)
2739 : _zmap_get_lyr_checked(lyr,basescr);
2740 }
2741
2742 if(!(basescr->valid&mVALID))
2743 {
2744 // rectfill(dest,x,y,x+255,y+175,dvc(0+1));
2745 rectfill(dest,x,y,x+255,y+175,vc(1));
2746
2747 if(ShowMisalignments)
2748 {
2749 check_alignments(dest,x,y,screen);
2750 }
2751
2752 return;
2753 }
2754
2755 if(LayerMaskInt[0]==0 || !get_qr(qr_CLASSIC_DRAWING_ORDER))
2756 {
2757 byte bgfill = 0;
2758 if (LayerDitherBG > -1)
2759 bgfill = vc(LayerDitherBG);
2760 rectfill(dest,x,y,x+255,y+175,bgfill);
2761 }
2762
2763 if(olddraw)
2764 {
2765 if(XOR(basescr->flags7&fLAYER2BG,ViewLayer2BG))
2766 _zmap_drawlayer(dest, x, y, layers[2], antiflags, false, false, HL_LAYER(2));
2767 _zmap_draw_ffc_layer(dest, x, y, flags, basescr, -2);
2768 }
2769 else for (int lyr = -7; lyr < -3; ++lyr)
2770 _zmap_draw_ffc_layer(dest, x, y, flags, basescr, lyr);
2771
2772 if(XOR(basescr->flags7&fLAYER3BG,ViewLayer3BG))
2773 _zmap_drawlayer(dest, x, y, layers[3], antiflags, basescr->layeropacity[3-1]!=255, XOR(basescr->flags7&fLAYER2BG,ViewLayer2BG), HL_LAYER(3));
2774 _zmap_draw_ffc_layer(dest, x, y, flags, basescr, -3);
2775
2776 if(!olddraw)
2777 {
2778 if(XOR(basescr->flags7&fLAYER2BG,ViewLayer2BG))
2779 _zmap_drawlayer(dest, x, y, layers[2], antiflags, false, true, HL_LAYER(2));
2780 _zmap_draw_ffc_layer(dest, x, y, flags, basescr, -2);
2781 }
2782 _zmap_draw_ffc_layer(dest, x, y, flags, basescr, -1);
2783
2784 _zmap_drawlayer(dest, x, y, layers[0], antiflags, false, !olddraw || (XOR(basescr->flags7&fLAYER2BG,ViewLayer2BG)||XOR(basescr->flags7&fLAYER3BG,ViewLayer3BG)), HL_LAYER(0), true);
2785 _zmap_draw_ffc_layer(dest, x, y, flags, basescr, 0);
2786
2787
2788 _zmap_drawlayer(dest, x, y, layers[1], antiflags, basescr->layeropacity[1-1]!=255, true, HL_LAYER(1));
2789 _zmap_draw_ffc_layer(dest, x, y, flags, basescr, 1);
2790
2791 if(!XOR(basescr->flags7&fLAYER2BG,ViewLayer2BG))
2792 _zmap_drawlayer(dest, x, y, layers[2], antiflags, basescr->layeropacity[2-1]!=255, true, HL_LAYER(2));
2793 _zmap_draw_ffc_layer(dest, x, y, flags, basescr, 2);
2794
2795 struct DoorDrawData
2796 {
2797 int over_pos; // Position for over_door (dBOMB)
2798 int put_pos; // Position for put_door (standard doors)
2799 int walk_x; // Pre-calculated X offset for dWALK
2800 int walk_y; // Pre-calculated Y offset for dWALK
2801 };
2802
2803 static const DoorDrawData door_data[4] = {
2804 // over, put, walk_x, walk_y
2805 { 39, 7, 120, 16 }, // up
2806 { 135, 151, 120, 144 }, // down
2807 { 66, 64, 16, 80 }, // left
2808 { 77, 78, 224, 80 } // right
2809 };
2810
2811 auto door_set = DoorComboSets[screens[cursor.screen].door_combo_set];
2812 bool walk_trans = get_bit(door_set.flags, df_walktrans);
2813
2814 int32_t doortype[4];
2815 for(int32_t i=0; i<4; i++)
2816 {
2817 switch(basescr->door[i])
2818 {
2819 case dOPEN: doortype[i]=dt_pass; break;
2820 case dLOCKED: doortype[i]=dt_lock; break;
2821 case d1WAYSHUTTER:
2822 case dSHUTTER: doortype[i]=dt_shut; break;
2823 case dBOSS: doortype[i]=dt_boss; break;
2824 case dBOMB: doortype[i]=dt_bomb; break;
2825 default: doortype[i]=0; // Default or unhandled
2826 }
2827 }
2828
2829 for (int i = 0; i < 4; ++i)
2830 {
2831 const auto& d = door_data[i];
2832 const int current_door_type_id = basescr->door[i];
2833
2834 switch (current_door_type_id) {
2835 case dBOMB:
2836 // Draw bombable overlay, then fall through to draw the door
2837 over_door(dest, d.over_pos, i, x, y, false, screen);
2838 [[fallthrough]];
2839
2840 case dOPEN:
2841 case dLOCKED:
2842 case d1WAYSHUTTER:
2843 case dSHUTTER:
2844 case dBOSS:
2845 {
2846 put_door(dest, d.put_pos, i, doortype[i], x, y, false, screen);
2847 break;
2848 }
2849
2850 case dWALK:
2851 if (walk_trans) {
2852 overcombo(dest, d.walk_x + x, d.walk_y + y,
2853 door_set.walkthroughcombo[i],
2854 door_set.walkthroughcset[i]);
2855 } else {
2856 put_combo(dest, d.walk_x + x, d.walk_y + y,
2857 door_set.walkthroughcombo[i],
2858 door_set.walkthroughcset[i], 0, 0);
2859 }
2860 break;
2861 }
2862 }
2863
2864 if((basescr->hasitem != 0) && !(flags&cNOITEM))
2865 {
2866 putitem2(dest,basescr->itemx+x,basescr->itemy+y+1-(get_qr(qr_NOITEMOFFSET)),basescr->item,lens_hint_item[basescr->item][0],lens_hint_item[basescr->item][1], 0);
2867 }
2868
2869 if(!XOR(basescr->flags7&fLAYER3BG,ViewLayer3BG))
2870 _zmap_drawlayer(dest, x, y, layers[3], antiflags, basescr->layeropacity[3-1]!=255, true, HL_LAYER(3));
2871 _zmap_draw_ffc_layer(dest, x, y, flags, basescr, 3);
2872
2873 _zmap_drawlayer(dest, x, y, layers[4], antiflags, basescr->layeropacity[4-1]!=255, true, HL_LAYER(4));
2874 _zmap_draw_ffc_layer(dest, x, y, flags, basescr, 4);
2875
2876 _zmap_drawlayer_ohead(dest, x, y, layers[0], antiflags, false, HL_LAYER(0));
2877
2878 if(get_qr(qr_OVERHEAD_COMBOS_L1_L2))
2879 {
2880 _zmap_drawlayer_ohead(dest, x, y, layers[1], antiflags, basescr->layeropacity[1-1]!=255, HL_LAYER(1));
2881 _zmap_drawlayer_ohead(dest, x, y, layers[2], antiflags, basescr->layeropacity[2-1]!=255, HL_LAYER(2));
2882 }
2883 _zmap_drawlayer(dest, x, y, layers[5], antiflags, basescr->layeropacity[5-1]!=255, true, HL_LAYER(5));
2884 _zmap_draw_ffc_layer(dest, x, y, flags, basescr, 5);
2885
2886 _zmap_draw_ffc_layer(dest, x, y, flags, basescr, -1);
2887
2888 _zmap_drawlayer(dest, x, y, layers[6], antiflags, basescr->layeropacity[6-1]!=255, true, HL_LAYER(6));
2889 _zmap_draw_ffc_layer(dest, x, y, flags, basescr, 6);
2890 _zmap_draw_ffc_layer(dest, x, y, flags, basescr, 7);
2891
2892 int num_ffcs = basescr->numFFC();
2893 for(int32_t i=num_ffcs-1; i>=0; i--) // changer ffcs
2894 if(basescr->ffcs[i].data)
2895 if(basescr->ffcs[i].flags&ffc_changer)
2896 putpixel(dest,(basescr->ffcs[i].x.getInt())+x,(basescr->ffcs[i].y.getInt())+y,vc(zc_oldrand()%16));
2897
2898 if(flags&cWALK)
2899 {
2900 if(layers[0])
2901 for(int32_t i=0; i<176; i++)
2902 put_walkflags(dest,((i&15)<<4)+x,(i&0xF0)+y,layers[0]->data[i], 0);
2903
2904 for(int32_t k=0; k<2; k++)
2905 {
2906 if(layers[k+1])
2907 for(int32_t i=0; i<176; i++)
2908 put_walkflags(dest,((i&15)<<4)+x,(i&0xF0)+y,layers[k+1]->data[i], 0);
2909 }
2910 for(int32_t i=num_ffcs-1; i>=0; i--)
2911 {
2912 if(auto data = basescr->ffcs[i].data)
2913 {
2914 if(!(basescr->ffcs[i].flags&ffc_changer))
2915 {
2916 newcombo const& cmb = combobuf[data];
2917 int32_t tx=(basescr->ffcs[i].x.getInt())+x;
2918 int32_t ty=(basescr->ffcs[i].y.getInt())+y;
2919
2920 if(basescr->ffcs[i].flags&ffc_solid)
2921 {
2922 rectfill(dest, tx, ty, tx + basescr->ffEffectWidth(i) - 1, ty + basescr->ffEffectHeight(i) - 1, COLOR_SOLID);
2923 }
2924
2925 if(cmb.type == cSLOPE)
2926 {
2927 slope_info s(cmb, tx, ty);
2928 s.draw(dest, 0, 0, COLOR_SLOPE);
2929 }
2930 }
2931 }
2932 }
2933 }
2934
2935 if(flags&cFLAGS)
2936 {
2937 if(LayerMaskInt[CurrentLayer]!=0)
2938 {
2939 int32_t _lscr=(basescr->layermap[CurrentLayer-1]-1)*MAPSCRS+basescr->layerscreen[CurrentLayer-1];
2940 auto* scr = _lscr>-1 && _lscr<map_count*MAPSCRS ? &TheMaps[_lscr] : nullptr;
2941
2942 for(int32_t i=0; i<176; i++)
2943 {
2944 if(CurrentLayer==0)
2945 {
2946 put_flags(dest,((i&15)<<4)+x,(i&0xF0)+y,basescr->data[i],basescr->cset[i],flags,basescr->sflag[i]);
2947 }
2948 else
2949 {
2950 if(prv_mode)
2951 {
2952 put_flags(dest,((i&15)<<4)+x,(i&0xF0)+y,prvlayers[CurrentLayer-1].data[i],prvlayers[CurrentLayer-1].cset[i],flags,prvlayers[CurrentLayer-1].sflag[i]);
2953 }
2954 else if(basescr->layermap[CurrentLayer-1] > 0)
2955 {
2956 if(scr)
2957 {
2958 put_flags(dest,((i&15)<<4)+x,(i&0xF0)+y,
2959 scr->data[i],
2960 scr->cset[i], flags,
2961 scr->sflag[i]);
2962 }
2963 }
2964 }
2965 }
2966 }
2967 }
2968
2969 int32_t dark = basescr->flags&cDARK;
2970
2971 if(dark && !(flags&cNODARK)
2972 && !((Flags&cNEWDARK) && get_qr(qr_NEW_DARKROOM)))
2973 {
2974 int col = vc(blackout_color);
2975 for(int32_t j=0; j<80; j++) {
2976 // Logic: ((i^j)&1)==0 means parity matches
2977 int start = (j&1);
2978 for(int32_t i=start; i<(80)-j; i+=2) {
2979 putpixel(dest,x+i,y+j,col);
2980 }
2981 }
2982 }
2983
2984 if(ShowMisalignments)
2985 {
2986 check_alignments(dest,x,y,screen);
2987 }
2988 }
2989
2990 void zmap::drawrow(BITMAP* dest,int32_t x,int32_t y,int32_t flags,int32_t c,int32_t map,int32_t scr)
2991 {
2992 if(map<0)
2993 map=cursor.map;
2994
2995 if(scr<0)
2996 scr=cursor.screen;
2997
2998 mapscr* layer=AbsoluteScr(map,scr);
2999 int32_t layermap=0, layerscreen=0;
3000
3001 if(!(layer->valid&mVALID))
3002 {
3003 // rectfill(dest,x,y,x+255,y+15,dvc(0+1));
3004 rectfill(dest,x,y,x+255,y+15,vc(1));
3005 return;
3006 }
3007
3008 int32_t dark = layer->flags&4;
3009
3010 if(LayerMaskInt[0]==0)
3011 {
3012 rectfill(dest,x,y,x+255,y+15,0);
3013 }
3014
3015 bool olddraw = get_qr(qr_CLASSIC_DRAWING_ORDER);
3016 int order[2] = {2,1};
3017 if (olddraw) zc_swap(order[0],order[1]);
3018 for(int k : order)
3019 {
3020 if(LayerMaskInt[k+1]!=0 && (k==1)?(layer->flags7&fLAYER2BG):(layer->flags7&fLAYER3BG))
3021 {
3022 layermap=layer->layermap[k]-1;
3023
3024 if(layermap>-1 && layermap<map_count)
3025 {
3026 layerscreen=layermap*MAPSCRS+layer->layerscreen[2-1];
3027
3028 for(int32_t i=c; i<(c&0xF0)+16; i++)
3029 {
3030 auto data = TheMaps[layerscreen].data[i];
3031 auto cs = TheMaps[layerscreen].cset[i];
3032 drawcombo(dest,((i&15)<<4)+x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3033 }
3034 }
3035 }
3036 }
3037
3038 if(LayerMaskInt[0]!=0)
3039 {
3040 for(int32_t i=c; i<(c&0xF0)+16; i++)
3041 {
3042 word cmbdat = (i < 176 ? layer->data[i] : 0);
3043 byte cmbcset = (i < 176 ? layer->cset[i] : 0);
3044 int32_t cmbflag = (i < 176 ? layer->sflag[i] : 0);
3045 drawcombo(dest,((i&15)<<4)+x,y,cmbdat,cmbcset,((flags|dark)&~cWALK),
3046 cmbflag,!olddraw || (layer->flags7&fLAYER3BG||layer->flags7&fLAYER2BG));
3047 }
3048 }
3049
3050 for(int32_t k=0; k<2; k++)
3051 {
3052 if(LayerMaskInt[k+1]!=0 && !(k==1 && layer->flags7&fLAYER2BG))
3053 {
3054 layermap=layer->layermap[k]-1;
3055
3056 if(layermap>-1 && layermap<map_count)
3057 {
3058 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3059
3060 for(int32_t i=c; i<(c&0xF0)+16; i++)
3061 {
3062 auto data = TheMaps[layerscreen].data[i];
3063 auto cs = TheMaps[layerscreen].cset[i];
3064 drawcombo(dest,((i&15)<<4)+x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3065 }
3066 }
3067 }
3068 }
3069
3070 int32_t doortype[4];
3071
3072 for(int32_t i=0; i<4; i++)
3073 {
3074 switch(layer->door[i])
3075 {
3076 case dOPEN:
3077 doortype[i]=dt_pass;
3078 break;
3079
3080 case dLOCKED:
3081 doortype[i]=dt_lock;
3082 break;
3083
3084 case d1WAYSHUTTER:
3085 case dSHUTTER:
3086 doortype[i]=dt_shut;
3087 break;
3088
3089 case dBOSS:
3090 doortype[i]=dt_boss;
3091 break;
3092
3093 case dBOMB:
3094 doortype[i]=dt_bomb;
3095 break;
3096 }
3097 }
3098
3099 if(c<16)
3100 {
3101 switch(layer->door[up])
3102 {
3103 case dBOMB:
3104 case dOPEN:
3105 case dLOCKED:
3106 case d1WAYSHUTTER:
3107 case dSHUTTER:
3108 case dBOSS:
3109 put_door(dest,7,up,doortype[up],x,y+176,true,scr);
3110 break;
3111 }
3112 }
3113 else if(c>159)
3114 {
3115 switch(layer->door[down])
3116 {
3117 case dBOMB:
3118 case dOPEN:
3119 case dLOCKED:
3120 case d1WAYSHUTTER:
3121 case dSHUTTER:
3122 case dBOSS:
3123 put_door(dest,151,down,doortype[down],x,y-16,true,scr);
3124 break;
3125 }
3126 }
3127
3128 for(int32_t k=2; k<4; k++)
3129 {
3130 if(LayerMaskInt[k+1]!=0 && !(k==2 && layer->flags7&fLAYER3BG))
3131 {
3132 layermap=layer->layermap[k]-1;
3133
3134 if(layermap>-1 && layermap<map_count)
3135 {
3136 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3137
3138 for(int32_t i=c; i<(c&0xF0)+16; i++)
3139 {
3140 if(layer->layeropacity[k]<255)
3141 {
3142 overcombotranslucent(dest,((i&15)<<4)+x,y,TheMaps[layerscreen].data[i],TheMaps[layerscreen].cset[i],layer->layeropacity[k]);
3143 }
3144 else
3145 {
3146 overcombo(dest,((i&15)<<4)+x,y,TheMaps[layerscreen].data[i],TheMaps[layerscreen].cset[i]);
3147 }
3148 }
3149 }
3150 }
3151 }
3152
3153 //Overhead L0
3154 if(LayerMaskInt[0]!=0)
3155 {
3156 for(int32_t i=c; i<(c&0xF0)+16; i++)
3157 {
3158 int32_t ct1=layer->data[i];
3159 int32_t ct3=combobuf[ct1].type;
3160
3161 if(combo_class_buf[ct3].overhead)
3162 {
3163 drawcombo(dest,((i&15)<<4)+x,y,layer->data[i],layer->cset[i],0,0);
3164 }
3165 }
3166 }
3167
3168 //Overhead L1/2
3169 if(get_qr(qr_OVERHEAD_COMBOS_L1_L2))
3170 {
3171 for(int32_t k = 0; k < 2; ++k)
3172 {
3173 if(LayerMaskInt[k+1]!=0)
3174 {
3175 layermap=layer->layermap[k]-1;
3176
3177 if(layermap>-1 && layermap<map_count)
3178 {
3179 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3180 for(int32_t i=c; i<(c&0xF0)+16; i++)
3181 {
3182 auto data = TheMaps[layerscreen].data[i];
3183 if(!combo_class_buf[combobuf[data].type].overhead) continue;
3184 auto cs = TheMaps[layerscreen].cset[i];
3185 drawcombo(dest,((i&15)<<4)+x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3186 }
3187 }
3188 }
3189 }
3190 }
3191
3192 for(int32_t k=4; k<6; k++)
3193 {
3194 if(LayerMaskInt[k+1]!=0)
3195 {
3196 layermap=layer->layermap[k]-1;
3197
3198 if(layermap>-1 && layermap<map_count)
3199 {
3200 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3201
3202 for(int32_t i=c; i<(c&0xF0)+16; i++)
3203 {
3204 auto data = TheMaps[layerscreen].data[i];
3205 auto cs = TheMaps[layerscreen].cset[i];
3206 drawcombo(dest,((i&15)<<4)+x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3207 }
3208 }
3209 }
3210 }
3211
3212 if(flags&cWALK)
3213 {
3214 if(LayerMaskInt[0]!=0)
3215 {
3216 for(int32_t i=c; i<(c&0xF0)+16; i++)
3217 {
3218 put_walkflags_layered_external(dest,((i&15)<<4)+x,y,i, -1, map,scr);
3219 }
3220 }
3221
3222 for(int32_t k=0; k<2; k++)
3223 {
3224 if(LayerMaskInt[k+1]!=0)
3225 {
3226 for(int32_t i=c; i<(c&0xF0)+16; i++)
3227 {
3228 put_walkflags_layered_external(dest,((i&15)<<4)+x,y,i, k, map,scr);
3229 }
3230 }
3231 }
3232 }
3233
3234 if(flags&cFLAGS)
3235 {
3236 if(LayerMaskInt[CurrentLayer]!=0)
3237 {
3238 for(int32_t i=c; i<(c&0xF0)+16; i++)
3239 {
3240 if(CurrentLayer==0)
3241 {
3242 put_flags(dest,((i&15)<<4)+x,/*(i&0xF0)+*/y,layer->data[i],layer->cset[i],flags|dark,layer->sflag[i]);
3243 }
3244 else
3245 {
3246 int32_t _lscr=(layer->layermap[CurrentLayer-1]-1)*MAPSCRS+layer->layerscreen[CurrentLayer-1];
3247
3248 if(_lscr>-1 && _lscr<map_count*MAPSCRS)
3249 {
3250 if(i < 176)
3251 {
3252 put_flags(dest,((i&15)<<4)+x,/*(i&0xF0)+*/y,
3253 TheMaps[_lscr].data[i],
3254 TheMaps[_lscr].cset[i], flags|dark,
3255 TheMaps[_lscr].sflag[i]);
3256 }
3257 else
3258 {
3259 put_flags(dest,((i&15)<<4)+x,/*(i&0xF0)+*/y,0,0, flags|dark,0);
3260 }
3261 }
3262 }
3263 }
3264 }
3265
3266 /*
3267 if (LayerMaskInt[0]!=0) {
3268 for(int32_t i=c; i<(c&0xF0)+16; i++) {
3269 put_flags(dest,((i&15)<<4)+x,y,layer->data[i],layer->cset[i],flags|dark,layer->sflag[i]);
3270 }
3271 }
3272 */
3273 }
3274
3275 if(ShowMisalignments)
3276 {
3277 if(c<16)
3278 {
3279 check_alignments(dest,x,y,scr);
3280 }
3281 else if(c>159)
3282 {
3283 check_alignments(dest,x,y-160,scr);
3284 }
3285 }
3286 }
3287
3288 void zmap::drawcolumn(BITMAP* dest,int32_t x,int32_t y,int32_t flags,int32_t c,int32_t map,int32_t scr)
3289 {
3290 if(map<0)
3291 map=cursor.map;
3292
3293 if(scr<0)
3294 scr=cursor.screen;
3295
3296 mapscr* layer=AbsoluteScr(map,scr);
3297 int32_t layermap=0, layerscreen=0;
3298
3299 if(!(layer->valid&mVALID))
3300 {
3301 // rectfill(dest,x,y,x+15,y+175,dvc(0+1));
3302 rectfill(dest,x,y,x+15,y+175,vc(1));
3303 return;
3304 }
3305
3306 int32_t dark = layer->flags&4;
3307
3308 if(LayerMaskInt[0]==0)
3309 {
3310 rectfill(dest,x,y,x+15,y+175,0);
3311 }
3312
3313 bool olddraw = get_qr(qr_CLASSIC_DRAWING_ORDER);
3314 int order[2] = {2,1};
3315 if (olddraw) zc_swap(order[0],order[1]);
3316 for(int k : order)
3317 {
3318 if(LayerMaskInt[k+1]!=0 && (k==1)?(layer->flags7&fLAYER2BG):(layer->flags7&fLAYER3BG))
3319 {
3320 layermap=layer->layermap[k]-1;
3321
3322 if(layermap>-1 && layermap<map_count)
3323 {
3324 layerscreen=layermap*MAPSCRS+layer->layerscreen[2-1];
3325
3326 for(int32_t i=c; i<176; i+=16)
3327 {
3328 auto data = TheMaps[layerscreen].data[i];
3329 auto cs = TheMaps[layerscreen].cset[i];
3330 drawcombo(dest,x,(i&0xF0)+y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3331 }
3332 }
3333 }
3334 }
3335
3336 if(LayerMaskInt[0]!=0)
3337 {
3338 for(int32_t i=c; i<176; i+=16)
3339 {
3340 word cmbdat = layer->data[i];
3341 byte cmbcset = layer->cset[i];
3342 int32_t cmbflag = layer->sflag[i];
3343 drawcombo(dest,x,(i&0xF0)+y,cmbdat,cmbcset,((flags|dark)&~cWALK),cmbflag,
3344 !olddraw || (layer->flags7&fLAYER3BG||layer->flags7&fLAYER2BG));
3345 }
3346 }
3347
3348 for(int32_t k=0; k<2; k++)
3349 {
3350 if(LayerMaskInt[k+1]!=0 && !(k==1 && layer->flags7&fLAYER2BG))
3351 {
3352 layermap=layer->layermap[k]-1;
3353
3354 if(layermap>-1 && layermap<map_count)
3355 {
3356 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3357
3358 for(int32_t i=c; i<176; i+=16)
3359 {
3360 auto data = TheMaps[layerscreen].data[i];
3361 auto cs = TheMaps[layerscreen].cset[i];
3362 drawcombo(dest,x,(i&0xF0)+y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3363 }
3364 }
3365 }
3366 }
3367
3368 int32_t doortype[4];
3369
3370 for(int32_t i=0; i<4; i++)
3371 {
3372 switch(layer->door[i])
3373 {
3374 case dOPEN:
3375 doortype[i]=dt_pass;
3376 break;
3377
3378 case dLOCKED:
3379 doortype[i]=dt_lock;
3380 break;
3381
3382 case d1WAYSHUTTER:
3383 case dSHUTTER:
3384 doortype[i]=dt_shut;
3385 break;
3386
3387 case dBOSS:
3388 doortype[i]=dt_boss;
3389 break;
3390
3391 case dBOMB:
3392 doortype[i]=dt_bomb;
3393 break;
3394 }
3395 }
3396
3397 if((c&0x0F)==0)
3398 {
3399 switch(layer->door[left])
3400 {
3401
3402 case dBOMB:
3403 case dOPEN:
3404 case dLOCKED:
3405 case d1WAYSHUTTER:
3406 case dSHUTTER:
3407 case dBOSS:
3408 // put_door(dest,64,left,doortype[left],x+256,y,true);
3409 put_door(dest,64,left,doortype[left],x,y,true,scr);
3410 break;
3411 }
3412 }
3413 else if((c&0x0F)==15)
3414 {
3415 switch(layer->door[right])
3416 {
3417 case dBOMB:
3418 case dOPEN:
3419 case dLOCKED:
3420 case d1WAYSHUTTER:
3421 case dSHUTTER:
3422 case dBOSS:
3423 put_door(dest,78,right,doortype[right],x-16,y,true,scr);
3424 break;
3425 }
3426 }
3427
3428 for(int32_t k=2; k<4; k++)
3429 {
3430 if(LayerMaskInt[k+1]!=0 && !(k==2 && layer->flags7&fLAYER3BG))
3431 {
3432 layermap=layer->layermap[k]-1;
3433
3434 if(layermap>-1 && layermap<map_count)
3435 {
3436 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3437
3438 for(int32_t i=c; i<176; i+=16)
3439 {
3440 auto data = TheMaps[layerscreen].data[i];
3441 auto cs = TheMaps[layerscreen].cset[i];
3442 drawcombo(dest,x,(i&0xF0)+y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3443 }
3444 }
3445 }
3446 }
3447
3448 //Overhead L0
3449 if(LayerMaskInt[0]!=0)
3450 {
3451 for(int32_t i=c; i<176; i+=16)
3452 {
3453 auto data = TheMaps[layerscreen].data[i];
3454 if(!combo_class_buf[combobuf[data].type].overhead) continue;
3455 auto cs = TheMaps[layerscreen].cset[i];
3456 drawcombo(dest,x,(i&0xF0)+y,data,cs,0,0);
3457 }
3458 }
3459 //Overhead L1/2
3460 if(get_qr(qr_OVERHEAD_COMBOS_L1_L2))
3461 {
3462 for(int32_t k = 0; k < 2; ++k)
3463 {
3464 if(LayerMaskInt[k+1]!=0)
3465 {
3466 layermap=layer->layermap[k]-1;
3467
3468 if(layermap>-1 && layermap<map_count)
3469 {
3470 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3471 for(int32_t i=c; i<176; i+=16)
3472 {
3473 auto data = TheMaps[layerscreen].data[i];
3474 if(!combo_class_buf[combobuf[data].type].overhead) continue;
3475 auto cs = TheMaps[layerscreen].cset[i];
3476 drawcombo(dest,x,(i&0xF0)+y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3477 }
3478 }
3479 }
3480 }
3481 }
3482
3483
3484 for(int32_t k=4; k<6; k++)
3485 {
3486 if(LayerMaskInt[k+1]!=0)
3487 {
3488 layermap=layer->layermap[k]-1;
3489
3490 if(layermap>-1 && layermap<map_count)
3491 {
3492 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3493
3494 for(int32_t i=c; i<176; i+=16)
3495 {
3496 auto data = TheMaps[layerscreen].data[i];
3497 auto cs = TheMaps[layerscreen].cset[i];
3498 drawcombo(dest,x,(i&0xF0)+y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3499 }
3500 }
3501 }
3502 }
3503
3504 if(flags&cWALK)
3505 {
3506 if(LayerMaskInt[0]!=0)
3507 {
3508 for(int32_t i=c&0xF; i<176; i+=16)
3509 {
3510 put_walkflags_layered_external(dest,x,y+(i&0xF0),i, -1, map,scr);
3511 }
3512 }
3513
3514 for(int32_t k=0; k<2; k++)
3515 {
3516 if(LayerMaskInt[k+1]!=0)
3517 {
3518 for(int32_t i=c&0xF; i<176; i+=16)
3519 {
3520 put_walkflags_layered_external(dest,x,y+(i&0xF0),i, k, map,scr);
3521 }
3522 }
3523 }
3524 }
3525
3526 if(flags&cFLAGS)
3527 {
3528 if(LayerMaskInt[CurrentLayer]!=0)
3529 {
3530 for(int32_t i=c; i<176; i+=16)
3531 {
3532 if(CurrentLayer==0)
3533 {
3534 put_flags(dest,/*((i&15)<<4)+*/x,(i&0xF0)+y,layer->data[i],layer->cset[i],flags|dark,layer->sflag[i]);
3535 }
3536 else
3537 {
3538 int32_t _lscr=(layer->layermap[CurrentLayer-1]-1)*MAPSCRS+layer->layerscreen[CurrentLayer-1];
3539
3540 if(_lscr>-1 && _lscr<map_count*MAPSCRS)
3541 {
3542 put_flags(dest,/*((i&15)<<4)+*/x,(i&0xF0)+y,
3543 TheMaps[_lscr].data[i],
3544 TheMaps[_lscr].cset[i], flags|dark,
3545 TheMaps[_lscr].sflag[i]);
3546 }
3547 }
3548 }
3549 }
3550 }
3551
3552 if(ShowMisalignments)
3553 {
3554 if((c&0x0F)==0)
3555 {
3556 check_alignments(dest,x,y,scr);
3557 }
3558 else if((c&0x0F)==15)
3559 {
3560 check_alignments(dest,x-240,y,scr);
3561 }
3562 }
3563 }
3564
3565 void zmap::drawblock(BITMAP* dest,int32_t x,int32_t y,int32_t flags,int32_t c,int32_t map,int32_t scr)
3566 {
3567 if(map<0)
3568 map=cursor.map;
3569
3570 if(scr<0)
3571 scr=cursor.screen;
3572
3573 mapscr* layer=AbsoluteScr(map,scr);
3574 int32_t layermap=0, layerscreen=0;
3575
3576 if(!(layer->valid&mVALID))
3577 {
3578 // rectfill(dest,x,y,x+15,y+15,dvc(0+1));
3579 rectfill(dest,x,y,x+15,y+15,vc(1));
3580 return;
3581 }
3582
3583 int32_t dark = layer->flags&4;
3584
3585 if(LayerMaskInt[0]!=0)
3586 {
3587 rectfill(dest,x,y,x+15,y+15,0);
3588 }
3589
3590 bool olddraw = get_qr(qr_CLASSIC_DRAWING_ORDER);
3591 int order[2] = {2,1};
3592 if (olddraw) zc_swap(order[0],order[1]);
3593 for(int k : order)
3594 {
3595 if(LayerMaskInt[k+1]!=0 && (k==1)?(layer->flags7&fLAYER2BG):(layer->flags7&fLAYER3BG))
3596 {
3597 layermap=layer->layermap[k]-1;
3598
3599 if(layermap>-1 && layermap<map_count)
3600 {
3601 layerscreen=layermap*MAPSCRS+layer->layerscreen[2-1];
3602
3603 auto data = TheMaps[layerscreen].data[c];
3604 auto cs = TheMaps[layerscreen].cset[c];
3605 drawcombo(dest,x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3606 }
3607 }
3608 }
3609
3610 if(LayerMaskInt[0]!=0)
3611 {
3612 word cmbdat = layer->data[c];
3613 byte cmbcset = layer->cset[c];
3614 int32_t cmbflag = layer->sflag[c];
3615 drawcombo(dest,x,y,cmbdat,cmbcset,((flags|dark)&~cWALK),cmbflag,
3616 !olddraw || (layer->flags7&fLAYER3BG||layer->flags7&fLAYER2BG));
3617 }
3618
3619
3620 for(int32_t k=0; k<2; k++)
3621 {
3622 if(LayerMaskInt[k+1]!=0)
3623 {
3624 layermap=layer->layermap[k]-1;
3625
3626 if(layermap>-1 && layermap<map_count)
3627 {
3628 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3629
3630 auto data = TheMaps[layerscreen].data[c];
3631 auto cs = TheMaps[layerscreen].cset[c];
3632 drawcombo(dest,x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3633 }
3634 }
3635 }
3636
3637 for(int32_t k=2; k<4; k++)
3638 {
3639 if(LayerMaskInt[k+1]!=0)
3640 {
3641 layermap=layer->layermap[k]-1;
3642
3643 if(layermap>-1 && layermap<map_count)
3644 {
3645 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3646 auto data = TheMaps[layerscreen].data[c];
3647 auto cs = TheMaps[layerscreen].cset[c];
3648 drawcombo(dest,x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3649 }
3650 }
3651 }
3652
3653 //Overhead L0
3654 if(LayerMaskInt[0]!=0)
3655 {
3656 auto data = TheMaps[layerscreen].data[c];
3657 if(combo_class_buf[combobuf[data].type].overhead)
3658 {
3659 auto cs = TheMaps[layerscreen].cset[c];
3660 drawcombo(dest,x,y,data,cs,0,0);
3661 }
3662 }
3663 //Overhead L1/2
3664 if(get_qr(qr_OVERHEAD_COMBOS_L1_L2))
3665 {
3666 for(int32_t k = 0; k < 2; ++k)
3667 {
3668 if(LayerMaskInt[k+1]!=0)
3669 {
3670 layermap=layer->layermap[k]-1;
3671
3672 if(layermap>-1 && layermap<map_count)
3673 {
3674 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3675 auto data = TheMaps[layerscreen].data[c];
3676 if(!combo_class_buf[combobuf[data].type].overhead) continue;
3677 auto cs = TheMaps[layerscreen].cset[c];
3678 drawcombo(dest,x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3679 }
3680 }
3681 }
3682 }
3683
3684
3685 for(int32_t k=4; k<6; k++)
3686 {
3687 if(LayerMaskInt[k+1]!=0)
3688 {
3689 layermap=layer->layermap[k]-1;
3690
3691 if(layermap>-1 && layermap<map_count)
3692 {
3693 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3694 auto data = TheMaps[layerscreen].data[c];
3695 auto cs = TheMaps[layerscreen].cset[c];
3696 drawcombo(dest,x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3697 }
3698 }
3699 }
3700
3701 if(flags&cWALK)
3702 {
3703 if(LayerMaskInt[0]!=0)
3704 {
3705 put_walkflags_layered_external(dest,x,y,c,-1, map,scr);
3706 }
3707
3708 for(int32_t k=0; k<2; k++)
3709 {
3710 if(LayerMaskInt[k+1]!=0)
3711 {
3712 put_walkflags_layered_external(dest,x,y,c,k, map,scr);
3713 }
3714 }
3715 }
3716
3717 if(flags&cFLAGS)
3718 {
3719 if(LayerMaskInt[CurrentLayer]!=0)
3720 {
3721 int32_t i = c;
3722 //for(int32_t i=c; i==c; i++)
3723 {
3724 if(CurrentLayer==0)
3725 {
3726 put_flags(dest,/*((i&15)<<4)+*/x,/*(i&0xF0)+*/y,layer->data[i],layer->cset[i],flags|dark,layer->sflag[i]);
3727 }
3728 else
3729 {
3730 int32_t _lscr=(layer->layermap[CurrentLayer-1]-1)*MAPSCRS+layer->layerscreen[CurrentLayer-1];
3731
3732 if(_lscr>-1 && _lscr<map_count*MAPSCRS)
3733 {
3734 put_flags(dest,/*((i&15)<<4)+*/x,/*(i&0xF0)+*/y,
3735 TheMaps[_lscr].data[i],
3736 TheMaps[_lscr].cset[i], flags|dark,
3737 TheMaps[_lscr].sflag[i]);
3738 }
3739 }
3740 }
3741 }
3742 }
3743
3744 if(ShowMisalignments)
3745 {
3746 switch(c)
3747 {
3748 case 0:
3749 check_alignments(dest,x,y,scr);
3750 break;
3751
3752 case 15:
3753 check_alignments(dest,x-240,y,scr);
3754 break;
3755
3756 case 160:
3757 check_alignments(dest,x,y-160,scr);
3758 break;
3759
3760 case 175:
3761 check_alignments(dest,x-240,y-160,scr);
3762 break;
3763 }
3764 }
3765 }
3766
3767 void zmap::drawstaticblock(BITMAP* dest,int32_t x,int32_t y)
3768 {
3769 if (InvalidBG == 2)
3770 {
3771 draw_checkerboard(dest, x, y, 16);
3772 }
3773 else if(InvalidBG == 1)
3774 {
3775 draw_static(dest, x, y, 16, 16);
3776 }
3777 else
3778 {
3779 rectfill(dest, x, y, x+15, y+15, vc(0));
3780 rect(dest, x, y, x+15, y+15, vc(15));
3781 line(dest, x, y, x+15, y+15, vc(15));
3782 line(dest, x, y+15, x+15, y, vc(15));
3783 }
3784 }
3785
3786 void zmap::drawstaticcolumn(BITMAP* dest,int32_t x,int32_t y)
3787 {
3788 if (InvalidBG == 2)
3789 {
3790 for(int32_t q = 0; q < 11; ++q)
3791 draw_checkerboard(dest, x, y + q * 16, 16);
3792 }
3793 else if(InvalidBG == 1)
3794 {
3795 draw_static(dest, x, y, 16, 176);
3796 }
3797 else
3798 {
3799 rectfill(dest, x, y, x+15, y+175, vc(0));
3800 rect(dest, x, y, x+15, y+175, vc(15));
3801 line(dest, x, y, x+15, y+175, vc(15));
3802 line(dest, x, y+175, x+15, y, vc(15));
3803 }
3804 }
3805
3806 void zmap::drawstaticrow(BITMAP* dest,int32_t x,int32_t y)
3807 {
3808 if (InvalidBG == 2)
3809 {
3810 for (int32_t q = 0; q < 16; ++q)
3811 draw_checkerboard(dest, x + q * 16, y, 16);
3812 }
3813 else if(InvalidBG == 1)
3814 {
3815 draw_static(dest, x, y, 256, 16);
3816 }
3817 else
3818 {
3819 rectfill(dest, x, y, x+255, y+15, vc(0));
3820 rect(dest, x, y, x+255, y+15, vc(15));
3821 line(dest, x, y, x+255, y+15, vc(15));
3822 line(dest, x, y+15, x+255, y, vc(15));
3823 }
3824 }
3825
3826 void zmap::draw_template(BITMAP* dest,int32_t x,int32_t y)
3827 {
3828 for(int32_t i=0; i<176; i++)
3829 {
3830 word cmbdat = screens[TEMPLATE].data[i];
3831 byte cmbcset = screens[TEMPLATE].cset[i];
3832 int32_t cmbflag = screens[TEMPLATE].sflag[i];
3833 put_combo(dest,((i&15)<<4)+x,(i&0xF0)+y,cmbdat,cmbcset,0,cmbflag);
3834 }
3835 }
3836
3837 void zmap::draw_template2(BITMAP* dest,int32_t x,int32_t y)
3838 {
3839 for(int32_t i=0; i<176; i++)
3840 {
3841 word cmbdat = screens[TEMPLATE2].data[i];
3842 byte cmbcset = screens[TEMPLATE2].cset[i];
3843 int32_t cmbflag = screens[TEMPLATE2].sflag[i];
3844 put_combo(dest,((i&15)<<4)+x,(i&0xF0)+y,cmbdat,cmbcset,0,cmbflag);
3845 }
3846 }
3847
3848 void zmap::draw_secret(BITMAP *dest, int32_t pos)
3849 {
3850 word cmbdat = screens[TEMPLATE].data[pos];
3851 byte cmbcset = screens[TEMPLATE].cset[pos];
3852 int32_t cmbflag = screens[TEMPLATE].sflag[pos];
3853 put_combo(dest,0,0,cmbdat,cmbcset,0,cmbflag);
3854 }
3855
3856 void zmap::draw_secret2(BITMAP *dest, int32_t scombo)
3857 {
3858 word cmbdat = screens[cursor.screen].secretcombo[scombo];
3859 byte cmbcset = screens[cursor.screen].secretcset[scombo];
3860 byte cmbflag = screens[cursor.screen].secretflag[scombo];
3861 put_combo(dest,0,0,cmbdat,cmbcset,0,cmbflag);
3862 }
3863
3864 void zmap::scroll(int32_t dir, bool warp)
3865 {
3866 if(cursor.map<map_count)
3867 {
3868 switch(dir)
3869 {
3870 case up:
3871 if(warp && Map.CurrScr()->flags2&wfUP)
3872 {
3873 dowarp(1,Map.CurrScr()->sidewarpindex&3);
3874 }
3875 else if(cursor.screen>15)
3876 {
3877 setCurrScr(cursor.screen - 16);
3878 }
3879
3880 break;
3881
3882 case down:
3883 if(warp && Map.CurrScr()->flags2&wfDOWN)
3884 {
3885 dowarp(1,(Map.CurrScr()->sidewarpindex>>2)&3);
3886 }
3887 else if(cursor.screen<MAPSCRS-16)
3888 {
3889 setCurrScr(cursor.screen + 16);
3890 }
3891
3892 break;
3893
3894 case left:
3895 if(warp && Map.CurrScr()->flags2&wfLEFT)
3896 {
3897 dowarp(1,(Map.CurrScr()->sidewarpindex>>4)&3);
3898 }
3899 else if(cursor.screen&15)
3900 {
3901 setCurrScr(cursor.screen - 1);
3902 }
3903
3904 break;
3905
3906 case right:
3907 if(warp && Map.CurrScr()->flags2&wfRIGHT)
3908 {
3909 dowarp(1,(Map.CurrScr()->sidewarpindex>>6)&3);
3910 }
3911 else if((cursor.screen&15)<15 && cursor.screen<MAPSCRS-1)
3912 {
3913 setCurrScr(cursor.screen + 1);
3914 }
3915
3916 break;
3917 }
3918 }
3919 }
3920
3921 void fetch_door(int side, int door, int dcs, word data[176], byte cset[176])
3922 {
3923 switch(side)
3924 {
3925 case up:
3926 switch(door)
3927 {
3928 case dWALL:
3929 case dBOMB:
3930 case dWALK:
3931 data[7] = DoorComboSets[dcs].doorcombo_u[dt_wall][0];
3932 cset[7] = DoorComboSets[dcs].doorcset_u[dt_wall][0];
3933 data[8] = DoorComboSets[dcs].doorcombo_u[dt_wall][1];
3934 cset[8] = DoorComboSets[dcs].doorcset_u[dt_wall][1];
3935 data[23] = DoorComboSets[dcs].doorcombo_u[dt_wall][2];
3936 cset[23] = DoorComboSets[dcs].doorcset_u[dt_wall][2];
3937 data[24] = DoorComboSets[dcs].doorcombo_u[dt_wall][3];
3938 cset[24] = DoorComboSets[dcs].doorcset_u[dt_wall][3];
3939 break;
3940
3941 default:
3942 data[7] = DoorComboSets[dcs].doorcombo_u[dt_pass][0];
3943 cset[7] = DoorComboSets[dcs].doorcset_u[dt_pass][0];
3944 data[8] = DoorComboSets[dcs].doorcombo_u[dt_pass][1];
3945 cset[8] = DoorComboSets[dcs].doorcset_u[dt_pass][1];
3946 data[23] = DoorComboSets[dcs].doorcombo_u[dt_pass][2];
3947 cset[23] = DoorComboSets[dcs].doorcset_u[dt_pass][2];
3948 data[24] = DoorComboSets[dcs].doorcombo_u[dt_pass][3];
3949 cset[24] = DoorComboSets[dcs].doorcset_u[dt_pass][3];
3950 break;
3951 }
3952
3953 break;
3954
3955 case down:
3956 switch(door)
3957 {
3958 case dWALL:
3959 case dBOMB:
3960 case dWALK:
3961 data[151] = DoorComboSets[dcs].doorcombo_d[dt_wall][0];
3962 cset[151] = DoorComboSets[dcs].doorcset_d[dt_wall][0];
3963 data[152] = DoorComboSets[dcs].doorcombo_d[dt_wall][1];
3964 cset[152] = DoorComboSets[dcs].doorcset_d[dt_wall][1];
3965 data[167] = DoorComboSets[dcs].doorcombo_d[dt_wall][2];
3966 cset[167] = DoorComboSets[dcs].doorcset_d[dt_wall][2];
3967 data[168] = DoorComboSets[dcs].doorcombo_d[dt_wall][3];
3968 cset[168] = DoorComboSets[dcs].doorcset_d[dt_wall][3];
3969 break;
3970
3971 default:
3972 data[151] = DoorComboSets[dcs].doorcombo_d[dt_pass][0];
3973 cset[151] = DoorComboSets[dcs].doorcset_d[dt_pass][0];
3974 data[152] = DoorComboSets[dcs].doorcombo_d[dt_pass][1];
3975 cset[152] = DoorComboSets[dcs].doorcset_d[dt_pass][1];
3976 data[167] = DoorComboSets[dcs].doorcombo_d[dt_pass][2];
3977 cset[167] = DoorComboSets[dcs].doorcset_d[dt_pass][2];
3978 data[168] = DoorComboSets[dcs].doorcombo_d[dt_pass][3];
3979 cset[168] = DoorComboSets[dcs].doorcset_d[dt_pass][3];
3980 break;
3981 }
3982
3983 break;
3984
3985 case left:
3986 switch(door)
3987 {
3988 case dWALL:
3989 case dBOMB:
3990 case dWALK:
3991 data[64] = DoorComboSets[dcs].doorcombo_l[dt_wall][0];
3992 cset[64] = DoorComboSets[dcs].doorcset_l[dt_wall][0];
3993 data[65] = DoorComboSets[dcs].doorcombo_l[dt_wall][1];
3994 cset[65] = DoorComboSets[dcs].doorcset_l[dt_wall][1];
3995 data[80] = DoorComboSets[dcs].doorcombo_l[dt_wall][2];
3996 cset[80] = DoorComboSets[dcs].doorcset_l[dt_wall][2];
3997 data[81] = DoorComboSets[dcs].doorcombo_l[dt_wall][3];
3998 cset[81] = DoorComboSets[dcs].doorcset_l[dt_wall][3];
3999 data[96] = DoorComboSets[dcs].doorcombo_l[dt_wall][4];
4000 cset[96] = DoorComboSets[dcs].doorcset_l[dt_wall][4];
4001 data[97] = DoorComboSets[dcs].doorcombo_l[dt_wall][5];
4002 cset[97] = DoorComboSets[dcs].doorcset_l[dt_wall][5];
4003 break;
4004
4005 default:
4006 data[64] = DoorComboSets[dcs].doorcombo_l[dt_pass][0];
4007 cset[64] = DoorComboSets[dcs].doorcset_l[dt_pass][0];
4008 data[65] = DoorComboSets[dcs].doorcombo_l[dt_pass][1];
4009 cset[65] = DoorComboSets[dcs].doorcset_l[dt_pass][1];
4010 data[80] = DoorComboSets[dcs].doorcombo_l[dt_pass][2];
4011 cset[80] = DoorComboSets[dcs].doorcset_l[dt_pass][2];
4012 data[81] = DoorComboSets[dcs].doorcombo_l[dt_pass][3];
4013 cset[81] = DoorComboSets[dcs].doorcset_l[dt_pass][3];
4014 data[96] = DoorComboSets[dcs].doorcombo_l[dt_pass][4];
4015 cset[96] = DoorComboSets[dcs].doorcset_l[dt_pass][4];
4016 data[97] = DoorComboSets[dcs].doorcombo_l[dt_pass][5];
4017 cset[97] = DoorComboSets[dcs].doorcset_l[dt_pass][5];
4018 break;
4019 }
4020
4021 break;
4022
4023 case right:
4024 switch(door)
4025 {
4026 case dWALL:
4027 case dBOMB:
4028 case dWALK:
4029 data[78] = DoorComboSets[dcs].doorcombo_r[dt_wall][0];
4030 cset[78] = DoorComboSets[dcs].doorcset_r[dt_wall][0];
4031 data[79] = DoorComboSets[dcs].doorcombo_r[dt_wall][1];
4032 cset[79] = DoorComboSets[dcs].doorcset_r[dt_wall][1];
4033 data[94] = DoorComboSets[dcs].doorcombo_r[dt_wall][2];
4034 cset[94] = DoorComboSets[dcs].doorcset_r[dt_wall][2];
4035 data[95] = DoorComboSets[dcs].doorcombo_r[dt_wall][3];
4036 cset[95] = DoorComboSets[dcs].doorcset_r[dt_wall][3];
4037 data[110] = DoorComboSets[dcs].doorcombo_r[dt_wall][4];
4038 cset[110] = DoorComboSets[dcs].doorcset_r[dt_wall][4];
4039 data[111] = DoorComboSets[dcs].doorcombo_r[dt_wall][5];
4040 cset[111] = DoorComboSets[dcs].doorcset_r[dt_wall][5];
4041 break;
4042
4043 default:
4044 data[78] = DoorComboSets[dcs].doorcombo_r[dt_pass][0];
4045 cset[78] = DoorComboSets[dcs].doorcset_r[dt_pass][0];
4046 data[79] = DoorComboSets[dcs].doorcombo_r[dt_pass][1];
4047 cset[79] = DoorComboSets[dcs].doorcset_r[dt_pass][1];
4048 data[94] = DoorComboSets[dcs].doorcombo_r[dt_pass][2];
4049 cset[94] = DoorComboSets[dcs].doorcset_r[dt_pass][2];
4050 data[95] = DoorComboSets[dcs].doorcombo_r[dt_pass][3];
4051 cset[95] = DoorComboSets[dcs].doorcset_r[dt_pass][3];
4052 data[110] = DoorComboSets[dcs].doorcombo_r[dt_pass][4];
4053 cset[110] = DoorComboSets[dcs].doorcset_r[dt_pass][4];
4054 data[111] = DoorComboSets[dcs].doorcombo_r[dt_pass][5];
4055 cset[111] = DoorComboSets[dcs].doorcset_r[dt_pass][5];
4056 break;
4057 }
4058
4059 break;
4060 }
4061 }
4062 void zmap::DoPutDoorCommand(int side, int door, bool force)
4063 {
4064 if(!force && screens[cursor.screen].door[side] == door)
4065 return;
4066 bool already_list = InListCommand();
4067 if(!already_list)
4068 StartListCommand();
4069 DoSetDoorCommand(cursor.screen,side,door);
4070 if(door != dNONE)
4071 {
4072 word data[176] = {0};
4073 byte cset[176] = {0};
4074 fetch_door(side, door, screens[cursor.screen].door_combo_set, data, cset);
4075 for(int q = 0; q < 176; ++q)
4076 if(data[q])
4077 DoSetComboCommand(cursor.map,cursor.screen,q,data[q],cset[q]);
4078 }
4079 if(!already_list)
4080 FinishListCommand();
4081 }
4082 void zmap::putdoor(int32_t screen,int32_t side,int32_t door)
4083 {
4084 if(screens[screen].door[side] == door)
4085 return;
4086
4087 screens[screen].door[side] = door;
4088 if(door != dNONE)
4089 {
4090 word data[176] = {0};
4091 byte cset[176] = {0};
4092 fetch_door(side, door, screens[screen].door_combo_set, data, cset);
4093 for(int q = 0; q < 176; ++q)
4094 if(data[q])
4095 {
4096 screens[screen].data[q] = data[q];
4097 screens[screen].cset[q] = cset[q];
4098 }
4099 }
4100 }
4101
4102 void list_command::execute()
4103 {
4104 for (auto command : commands)
4105 {
4106 command->execute();
4107 }
4108 }
4109
4110 void list_command::undo()
4111 {
4112 for (int i = commands.size() - 1; i >= 0; i--)
4113 {
4114 commands[i]->undo();
4115 }
4116 }
4117
4118 int list_command::size()
4119 {
4120 int s = 0;
4121 for (auto command : commands)
4122 {
4123 s += command->size();
4124 }
4125 return s;
4126 }
4127
4128 void set_combo_command::execute()
4129 {
4130 mapscr* scr_ptr = Map.AbsoluteScrMakeValid(map, scr);
4131 if (!scr_ptr) return;
4132
4133 if (combo != -1) scr_ptr->data[pos] = combo;
4134 scr_ptr->cset[pos] = cset;
4135 }
4136
4137 void set_combo_command::undo()
4138 {
4139 mapscr* mapscr_ptr = Map.AbsoluteScr(map, scr);
4140 if(!mapscr_ptr) return;
4141 if (combo != -1) mapscr_ptr->data[pos] = prev_combo;
4142 mapscr_ptr->cset[pos] = prev_cset;
4143 }
4144
4145 set_ffc_command::data_t set_ffc_command::create_data(const ffcdata& ffc)
4146 {
4147 std::array<int, 8> initd_arr;
4148 std::copy(std::begin(ffc.initd), std::end(ffc.initd), initd_arr.begin());
4149
4150 return {
4151 .x = ffc.x,
4152 .y = ffc.y,
4153 .vx = ffc.vx,
4154 .vy = ffc.vy,
4155 .ax = ffc.ax,
4156 .ay = ffc.ay,
4157 .data = ffc.data,
4158 .cset = ffc.cset,
4159 .delay = ffc.delay,
4160 .link = ffc.link,
4161 .script = ffc.script,
4162 .tw = ffc.txsz,
4163 .th = ffc.tysz,
4164 .ew = ffc.hit_width,
4165 .eh = ffc.hit_height,
4166 .flags = ffc.flags,
4167 .initd = initd_arr,
4168 .layer = ffc.layer
4169 };
4170 }
4171
4172 void set_ffc_command::execute()
4173 {
4174 mapscr* mapscr_ptr = Map.AbsoluteScrMakeValid(map, scr);
4175 if(!mapscr_ptr) return;
4176
4177 mapscr_ptr->valid |= mVALID;
4178 mapscr_ptr->ffcs[i].x = data.x;
4179 mapscr_ptr->ffcs[i].y = data.y;
4180 mapscr_ptr->ffcs[i].vx = data.vx;
4181 mapscr_ptr->ffcs[i].vy = data.vy;
4182 mapscr_ptr->ffcs[i].ax = data.ax;
4183 mapscr_ptr->ffcs[i].ay = data.ay;
4184 mapscr_ptr->ffcs[i].data = data.data;
4185 mapscr_ptr->ffcs[i].cset = data.cset;
4186 mapscr_ptr->ffcs[i].delay = data.delay;
4187 mapscr_ptr->ffcs[i].link = data.link;
4188 mapscr_ptr->ffcs[i].script = data.script;
4189 mapscr_ptr->ffcs[i].flags = data.flags;
4190 mapscr_ptr->ffEffectWidth(i, data.ew);
4191 mapscr_ptr->ffEffectHeight(i, data.eh);
4192 mapscr_ptr->ffTileWidth(i, data.tw);
4193 mapscr_ptr->ffTileHeight(i, data.th);
4194 std::copy(std::begin(data.initd), std::end(data.initd), std::begin(mapscr_ptr->ffcs[i].initd));
4195 mapscr_ptr->ffcs[i].layer = data.layer;
4196 mapscr_ptr->ffcCountMarkDirty();
4197 mapscr_ptr->ffcs[i].updateSolid();
4198 }
4199
4200 void set_ffc_command::undo()
4201 {
4202 mapscr* mapscr_ptr = Map.AbsoluteScr(map, scr);
4203 if(!mapscr_ptr) return;
4204
4205 mapscr_ptr->ffcs[i].x = prev_data.x;
4206 mapscr_ptr->ffcs[i].y = prev_data.y;
4207 mapscr_ptr->ffcs[i].vx = prev_data.vx;
4208 mapscr_ptr->ffcs[i].vy = prev_data.vy;
4209 mapscr_ptr->ffcs[i].ax = prev_data.ax;
4210 mapscr_ptr->ffcs[i].ay = prev_data.ay;
4211 mapscr_ptr->ffcs[i].data = prev_data.data;
4212 mapscr_ptr->ffcs[i].cset = prev_data.cset;
4213 mapscr_ptr->ffcs[i].delay = prev_data.delay;
4214 mapscr_ptr->ffcs[i].link = prev_data.link;
4215 mapscr_ptr->ffcs[i].script = prev_data.script;
4216 mapscr_ptr->ffcs[i].flags = prev_data.flags;
4217 mapscr_ptr->ffEffectWidth(i, prev_data.ew);
4218 mapscr_ptr->ffEffectHeight(i, prev_data.eh);
4219 mapscr_ptr->ffTileWidth(i, prev_data.tw);
4220 mapscr_ptr->ffTileHeight(i, prev_data.th);
4221 std::copy(std::begin(prev_data.initd), std::end(prev_data.initd), std::begin(mapscr_ptr->ffcs[i].initd));
4222 mapscr_ptr->ffcs[i].layer = prev_data.layer;
4223 mapscr_ptr->ffcCountMarkDirty();
4224 mapscr_ptr->ffcs[i].updateSolid();
4225 }
4226
4227 void set_flag_command::execute()
4228 {
4229 mapscr* mapscr_ptr = Map.AbsoluteScrMakeValid(map, scr);
4230 if(!mapscr_ptr) return;
4231
4232 mapscr_ptr->valid |= mVALID;
4233 mapscr_ptr->sflag[pos] = flag;
4234 }
4235
4236 void set_flag_command::undo()
4237 {
4238 mapscr* mapscr_ptr = Map.AbsoluteScr(map, scr);
4239 if(!mapscr_ptr) return;
4240 mapscr_ptr->sflag[pos] = prev_flag;
4241 }
4242
4243 void set_door_command::execute()
4244 {
4245 auto* mapscr_ptr = Map.AbsoluteScrMakeValid(cursor.map, cursor.screen);
4246 if(!mapscr_ptr) return;
4247
4248 mapscr_ptr->valid |= mVALID;
4249 mapscr_ptr->door[side] = door;
4250 }
4251
4252 void set_door_command::undo()
4253 {
4254 Map.AbsoluteScr(cursor.map, cursor.screen)->door[side] = prev_door;
4255 }
4256
4257 void set_dcs_command::execute()
4258 {
4259 auto* mapscr_ptr = Map.AbsoluteScrMakeValid(cursor.map, cursor.screen);
4260 if(!mapscr_ptr) return;
4261
4262 mapscr_ptr->valid |= mVALID;
4263 mapscr_ptr->door_combo_set = dcs;
4264 }
4265
4266 void set_dcs_command::undo()
4267 {
4268 Map.AbsoluteScr(cursor.map, cursor.screen)->door_combo_set = prev_dcs;
4269 }
4270
4271 void paste_screen_command::execute()
4272 {
4273 perform(screen.get());
4274 }
4275
4276 void paste_screen_command::undo()
4277 {
4278 if (prev_screens.size() > 1)
4279 {
4280 ASSERT(type == PasteCommandType::ScreenPartialToEveryScreen || type == PasteCommandType::ScreenAllToEveryScreen);
4281 ASSERT(prev_screens.size() == 128);
4282 for (int i = 0; i < 128; i++)
4283 {
4284 copy_mapscr(Map.AbsoluteScrMakeValid(cursor.map, i), prev_screens[i].get());
4285 // TODO: why not just this?
4286 // If this changes, also change the line in PasteAllToAll and PasteAll to use simply copy assignment.
4287 // *Map.AbsoluteScr(map, i) = *prev_screens[i].get();
4288 }
4289 return;
4290 }
4291
4292 perform(prev_screens[0].get());
4293 }
4294
4295 int paste_screen_command::size()
4296 {
4297 return prev_screens.size() + 1;
4298 }
4299
4300 void paste_screen_command::perform(mapscr* to)
4301 {
4302 if (to)
4303 {
4304 switch (type) {
4305 case ScreenAll: Map.PasteAll(*to, screen_index); break;
4306 case ScreenAllToEveryScreen: Map.PasteAllToAll(*to); break;
4307 case ScreenData: Map.PasteScreenData(*to, screen_index); break;
4308 case ScreenDoors: Map.PasteDoors(*to, screen_index); break;
4309 case ScreenEnemies: Map.PasteEnemies(*to, screen_index); break;
4310 case ScreenFFCombos: Map.PasteFFCombos(*to, screen_index); break;
4311 case ScreenGuy: Map.PasteGuy(*to, screen_index); break;
4312 case ScreenLayers: Map.PasteLayers(*to, screen_index); break;
4313 case ScreenPalette: Map.PastePalette(*to, screen_index); break;
4314 case ScreenPartial: Map.Paste(*to, screen_index); break;
4315 case ScreenPartialToEveryScreen: Map.PasteToAll(*to); break;
4316 case ScreenRoom: Map.PasteRoom(*to, screen_index); break;
4317 case ScreenSecretCombos: Map.PasteSecretCombos(*to, screen_index); break;
4318 case ScreenUnderCombo: Map.PasteUnderCombo(*to, screen_index); break;
4319 case ScreenWarpLocations: Map.PasteWarpLocations(*to, screen_index); break;
4320 case ScreenWarps: Map.PasteWarps(*to, screen_index); break;
4321 }
4322 }
4323 else
4324 {
4325 Map.clearscr(screen_index);
4326 }
4327 refresh(rALL);
4328 }
4329
4330 void set_screen_command::execute()
4331 {
4332 if (screen)
4333 {
4334 copy_mapscr(Map.AbsoluteScrMakeValid(cursor.map, screen_index), screen.get());
4335 }
4336 else
4337 {
4338 Map.clearscr(screen_index);
4339 }
4340 refresh(rALL);
4341 }
4342
4343 void set_screen_command::undo()
4344 {
4345 if (prev_screen)
4346 {
4347 copy_mapscr(Map.AbsoluteScrMakeValid(cursor.map, screen_index), prev_screen.get());
4348 }
4349 else
4350 {
4351 Map.clearscr(screen_index);
4352 }
4353 refresh(rALL);
4354 }
4355
4356 int set_screen_command::size()
4357 {
4358 return (prev_screen ? 1 : 0) + (screen ? 1 : 0);
4359 }
4360
4361 static std::shared_ptr<list_command> current_list_command;
4362 void zmap::StartListCommand()
4363 {
4364 ASSERT(!current_list_command);
4365 current_list_command.reset(new list_command);
4366 }
4367
4368 void zmap::FinishListCommand()
4369 {
4370 if (current_list_command->commands.size() == 1)
4371 {
4372 input_undo_stack.push_back(current_list_command->commands[0]);
4373 }
4374 else if (current_list_command->commands.size() > 1)
4375 {
4376 input_undo_stack.push_back(current_list_command);
4377 }
4378 CapCommandHistory();
4379 current_list_command = nullptr;
4380 }
4381
4382 void zmap::RevokeListCommand()
4383 {
4384 current_list_command->undo();
4385 current_list_command = nullptr;
4386 }
4387
4388 bool zmap::InListCommand() const
4389 {
4390 return current_list_command ? true : false;
4391 }
4392
4393 void zmap::ExecuteCommand(std::shared_ptr<user_input_command> command, bool skip_execute)
4394 {
4395 input_redo_stack = {};
4396
4397 if (!skip_execute) command->execute();
4398 if (current_list_command)
4399 {
4400 current_list_command->commands.push_back(command);
4401 if (current_list_command->commands.size() == 1)
4402 {
4403 current_list_command->cursor = command->cursor;
4404 }
4405 }
4406 else
4407 {
4408 input_undo_stack.push_back(command);
4409 CapCommandHistory();
4410 }
4411 mark_save_dirty();
4412 }
4413
4414 void zmap::UndoCommand()
4415 {
4416 if (input_undo_stack.size() <= 0) return;
4417
4418 // If not currently looking at the associated screen, first change the view
4419 // and wait for the next call to actually undo this command.
4420 auto command = input_undo_stack.back();
4421 if (command->cursor.map != Map.getCurrMap() || command->cursor.screen != Map.getCurrScr())
4422 {
4423 setCursor(command.get()->cursor);
4424 return;
4425 }
4426
4427 command->undo();
4428 input_redo_stack.push(command);
4429 input_undo_stack.pop_back();
4430 mark_save_dirty();
4431 }
4432
4433 void zmap::RedoCommand()
4434 {
4435 if (input_redo_stack.size() <= 0) return;
4436
4437 // If not currently selected the associated screen, first change the cursor
4438 // and wait for the next call to actually execute this command.
4439 auto command = input_redo_stack.top();
4440 if (command->cursor.map != Map.getCurrMap() || command->cursor.screen != Map.getCurrScr())
4441 {
4442 setCursor(command.get()->cursor);
4443 return;
4444 }
4445
4446 command->execute();
4447 input_undo_stack.push_back(command);
4448 input_redo_stack.pop();
4449 mark_save_dirty();
4450 }
4451
4452 11 void zmap::ClearCommandHistory()
4453 {
4454 11 current_list_command = nullptr;
4455 11 input_undo_stack = {};
4456 11 input_redo_stack = {};
4457 11 }
4458
4459 // Extra amount is from mapscr's vectors.
4460 static int size_of_mapscr = sizeof(mapscr) + 4*176;
4461 // Allow the undo system to use roughly 100 MB of memory.
4462 // This doesn't count the memory used by commands that don't store a mapscr,
4463 // but that should be negligible.
4464 12 static int max_command_size = 100e6 / size_of_mapscr;
4465 void zmap::CapCommandHistory()
4466 {
4467 int size;
4468 do
4469 {
4470 size = 0;
4471 for (auto command : input_undo_stack)
4472 {
4473 size += command->size();
4474 }
4475 if (size > max_command_size) input_undo_stack.pop_front();
4476 } while (size > max_command_size);
4477 }
4478
4479 void zmap::DoSetComboCommand(ComboPosition pos, int combo, int cset)
4480 {
4481 if (!pos.is_valid(cursor))
4482 return;
4483
4484 int map = cursor.map;
4485 int screen = cursor.viewscr + pos.screen_offset();
4486 if (!AbsoluteScr(map, screen))
4487 return;
4488
4489 if (CurrentLayer)
4490 {
4491 mapscr* scr = AbsoluteScrMakeValid(map, screen);
4492 map = scr->layermap[CurrentLayer-1]-1;
4493 screen = scr->layerscreen[CurrentLayer-1];
4494 }
4495 DoSetComboCommand(map, screen, pos.truncate(), combo, cset);
4496 }
4497
4498 void zmap::DoSetComboCommand(int map, int scr, int pos, int combo, int cset)
4499 {
4500 mapscr* mapscr_ptr = AbsoluteScrMakeValid(map, scr);
4501 if (!mapscr_ptr) return;
4502
4503 std::shared_ptr<set_combo_command> command(new set_combo_command);
4504 command->cursor = cursor;
4505 command->map = map;
4506 command->scr = scr;
4507 command->pos = pos;
4508 command->combo = combo;
4509 command->cset = cset;
4510 command->prev_combo = mapscr_ptr->data[pos];
4511 command->prev_cset = mapscr_ptr->cset[pos];
4512 if ((command->combo != -1 && command->prev_combo == command->combo) && command->cset == command->prev_cset)
4513 {
4514 // nothing to do...
4515 return;
4516 }
4517
4518 ExecuteCommand(command);
4519 }
4520
4521 void zmap::DoSetFFCCommand(int map, int scr, int i, set_ffc_command::data_t data)
4522 {
4523 mapscr* mapscr_ptr = Map.AbsoluteScr(map, scr);
4524 if(!mapscr_ptr) return;
4525
4526 mapscr_ptr->ensureFFC(i);
4527
4528 std::shared_ptr<set_ffc_command> command(new set_ffc_command);
4529
4530 std::array<int, 8> initd_arr;
4531 std::copy(std::begin(mapscr_ptr->ffcs[i].initd), std::end(mapscr_ptr->ffcs[i].initd), initd_arr.begin());
4532
4533 auto prev_data = set_ffc_command::create_data(mapscr_ptr->ffcs[i]);
4534
4535 command->cursor = cursor;
4536 command->map = map;
4537 command->scr = scr;
4538 command->i = i;
4539 command->data = data;
4540 command->prev_data = prev_data;
4541 if (data == prev_data)
4542 {
4543 // nothing to do...
4544 return;
4545 }
4546
4547 ExecuteCommand(command);
4548 }
4549
4550 void zmap::DoSetFlagCommand(ComboPosition pos, int flag)
4551 {
4552 if (!pos.is_valid(cursor))
4553 return;
4554
4555 int map = cursor.map;
4556 int screen = cursor.viewscr + pos.screen_offset();
4557 if (!AbsoluteScr(map, screen))
4558 return;
4559
4560 if (CurrentLayer)
4561 {
4562 mapscr* scr = AbsoluteScrMakeValid(map, screen);
4563 map = scr->layermap[CurrentLayer-1]-1;
4564 screen = scr->layerscreen[CurrentLayer-1];
4565 }
4566 DoSetFlagCommand(map, screen, pos.truncate(), flag);
4567 }
4568
4569 void zmap::DoSetFlagCommand(int map, int scr, int pos, int flag)
4570 {
4571 mapscr* mapscr_ptr = Map.AbsoluteScr(map, scr);
4572 if(!mapscr_ptr) return;
4573
4574 std::shared_ptr<set_flag_command> command(new set_flag_command);
4575 command->cursor = cursor;
4576 command->map = map;
4577 command->scr = scr;
4578 command->pos = pos;
4579 command->flag = flag;
4580 command->prev_flag = mapscr_ptr->sflag[pos];
4581 if (command->flag == command->prev_flag)
4582 {
4583 // nothing to do...
4584 return;
4585 }
4586
4587 ExecuteCommand(command);
4588 }
4589
4590 void zmap::DoSetDoorCommand(int scr, int side, int door)
4591 {
4592 if(screens[scr].door[side] == door)
4593 return;
4594 std::shared_ptr<set_door_command> command(new set_door_command);
4595 command->cursor = cursor;
4596 command->side = side;
4597 command->door = door;
4598 command->prev_door = screens[scr].door[side];
4599
4600 ExecuteCommand(command);
4601 }
4602 void zmap::DoSetDCSCommand(int dcs)
4603 {
4604 if(screens[cursor.screen].door_combo_set == dcs)
4605 return;
4606 std::shared_ptr<set_dcs_command> command(new set_dcs_command);
4607 command->cursor = cursor;
4608 command->dcs = dcs;
4609 command->prev_dcs = screens[cursor.screen].door_combo_set;
4610
4611 ExecuteCommand(command);
4612 }
4613
4614 void zmap::DoPasteScreenCommand(PasteCommandType type, int screen)
4615 {
4616 if (screen == -1)
4617 screen = cursor.screen;
4618
4619 std::shared_ptr<paste_screen_command> command(new paste_screen_command);
4620 command->cursor = cursor;
4621 command->type = type;
4622 command->screen = std::shared_ptr<mapscr>(new mapscr(copymapscr));
4623 command->screen_index = screen;
4624
4625 if (type == PasteCommandType::ScreenPartialToEveryScreen || type == PasteCommandType::ScreenAllToEveryScreen)
4626 {
4627 for (int i=0; i < 128; i++)
4628 {
4629 command->prev_screens.push_back(std::shared_ptr<mapscr>(new mapscr(screens[i])));
4630 }
4631 }
4632 else
4633 {
4634 command->prev_screens.push_back(std::shared_ptr<mapscr>(new mapscr(screens[screen])));
4635 }
4636
4637 ExecuteCommand(command);
4638 }
4639
4640 void zmap::DoClearScreenCommand(int screen)
4641 {
4642 std::shared_ptr<set_screen_command> command(new set_screen_command);
4643 command->cursor = cursor;
4644 command->prev_screen = std::shared_ptr<mapscr>(new mapscr(screens[screen]));
4645 command->screen = std::shared_ptr<mapscr>(nullptr);
4646 command->screen_index = screen;
4647
4648 ExecuteCommand(command);
4649 }
4650
4651 void zmap::DoTemplateCommand(int floorcombo, int floorcset, int screen)
4652 {
4653 std::shared_ptr<set_screen_command> command(new set_screen_command);
4654 command->cursor = cursor;
4655 command->prev_screen = std::shared_ptr<mapscr>(new mapscr(*Map.Scr(screen)));
4656 Template(floorcombo, floorcset, screen);
4657 command->screen = std::shared_ptr<mapscr>(new mapscr(*Map.Scr(screen)));
4658
4659 ExecuteCommand(command, true);
4660 }
4661
4662 void zmap::Copy(int scr)
4663 {
4664 if(screens[scr].valid&mVALID)
4665 {
4666 copy_mapscr(&copymapscr, &screens[scr]);
4667 //copymapscr=screens[scr];
4668 can_paste=true;
4669 copymap=cursor.map;
4670 copyscr=scr;
4671 copyscrdata = zinit.screen_data[cursor.map*MAPSCRS+scr];
4672 copyffc = -1;
4673 }
4674 }
4675
4676 void zmap::CopyFFC(int32_t screen, int32_t n)
4677 {
4678 if(screens[screen].valid&mVALID)
4679 {
4680 copy_mapscr(&copymapscr, &screens[screen]);
4681 // Can't paste the screen itself
4682 can_paste = false;
4683 copymap=cursor.map;
4684 copyscr=screen;
4685 copyffc = n;
4686 }
4687 }
4688
4689 void zmap::Paste(const mapscr& copymapscr, int screen)
4690 {
4691 if(can_paste)
4692 {
4693 if(!(screens[screen].valid&mVALID))
4694 {
4695 screens[screen].valid |= mVALID;
4696 screens[screen].color = copymapscr.color;
4697 }
4698
4699 screens[screen].door_combo_set = copymapscr.door_combo_set;
4700
4701 for(int32_t i=0; i<4; i++)
4702 {
4703 screens[screen].door[i]=copymapscr.door[i];
4704 }
4705
4706 for(int32_t i=0; i<176; i++)
4707 {
4708 screens[screen].data[i] = copymapscr.data[i];
4709 screens[screen].cset[i] = copymapscr.cset[i];
4710 screens[screen].sflag[i] = copymapscr.sflag[i];
4711 }
4712
4713 refresh_color();
4714
4715 mark_save_dirty();
4716 }
4717 }
4718
4719 void zmap::PasteUnderCombo(const mapscr& copymapscr, int screen)
4720 {
4721 if(can_paste)
4722 {
4723 screens[screen].undercombo = copymapscr.undercombo;
4724 screens[screen].undercset = copymapscr.undercset;
4725 mark_save_dirty();
4726 }
4727 }
4728
4729 void zmap::PasteSecretCombos(const mapscr& copymapscr, int screen)
4730 {
4731 if(can_paste)
4732 {
4733 for(int32_t i=0; i<128; i++)
4734 {
4735 screens[screen].secretcombo[i] = copymapscr.secretcombo[i];
4736 screens[screen].secretcset[i] = copymapscr.secretcset[i];
4737 screens[screen].secretflag[i] = copymapscr.secretflag[i];
4738 }
4739
4740 mark_save_dirty();
4741 }
4742 }
4743
4744 // TODO const mapscr& copymapscr
4745 void zmap::PasteFFCombos(mapscr& copymapscr, int screen)
4746 {
4747 if(can_paste)
4748 {
4749 screens[screen].ffcs = copymapscr.ffcs;
4750 screens[screen].ffcCountMarkDirty();
4751 mark_save_dirty();
4752 }
4753 }
4754
4755 void zmap::PasteWarps(const mapscr& copymapscr, int screen)
4756 {
4757 if(can_paste)
4758 {
4759 screens[screen].sidewarpindex = copymapscr.sidewarpindex;
4760
4761 for(int32_t i=0; i<4; i++)
4762 {
4763 screens[screen].tilewarptype[i] = copymapscr.tilewarptype[i];
4764 screens[screen].tilewarpdmap[i] = copymapscr.tilewarpdmap[i];
4765 screens[screen].tilewarpscr[i] = copymapscr.tilewarpscr[i];
4766 screens[screen].sidewarptype[i] = copymapscr.sidewarptype[i];
4767 screens[screen].sidewarpdmap[i] = copymapscr.sidewarpdmap[i];
4768 screens[screen].sidewarpscr[i] = copymapscr.sidewarpscr[i];
4769 screens[screen].flags2 &= ~(wfUP|wfDOWN|wfLEFT|wfRIGHT);
4770 screens[screen].flags2 |= copymapscr.flags2 & (wfUP|wfDOWN|wfLEFT|wfRIGHT);
4771 screens[screen].sidewarpoverlayflags = copymapscr.sidewarpoverlayflags;
4772 screens[screen].tilewarpoverlayflags = copymapscr.tilewarpoverlayflags;
4773 }
4774
4775 mark_save_dirty();
4776 }
4777 }
4778
4779 void zmap::PasteScreenData(const mapscr& copymapscr, int screen)
4780 {
4781 if(can_paste)
4782 {
4783 screens[screen].csensitive = copymapscr.csensitive;
4784 screens[screen].oceansfx = copymapscr.oceansfx;
4785 screens[screen].bosssfx = copymapscr.bosssfx;
4786 screens[screen].secretsfx = copymapscr.secretsfx;
4787 screens[screen].holdupsfx = copymapscr.holdupsfx;
4788 screens[screen].flags = copymapscr.flags;
4789 screens[screen].flags2 &= (wfUP|wfDOWN|wfLEFT|wfRIGHT);
4790 screens[screen].flags2 |= copymapscr.flags2 & ~(wfUP|wfDOWN|wfLEFT|wfRIGHT);
4791 screens[screen].flags3 = copymapscr.flags3;
4792 screens[screen].flags4 = copymapscr.flags4;
4793 screens[screen].flags5 = copymapscr.flags5;
4794 screens[screen].flags6 = copymapscr.flags6;
4795 screens[screen].flags7 = copymapscr.flags7;
4796 screens[screen].flags8 = copymapscr.flags8;
4797 screens[screen].flags9 = copymapscr.flags9;
4798 screens[screen].flags10 = copymapscr.flags10;
4799 screens[screen].flags11 = copymapscr.flags11;
4800 screens[screen].item = copymapscr.item;
4801 screens[screen].hasitem = copymapscr.hasitem;
4802 screens[screen].itemx = copymapscr.itemx;
4803 screens[screen].itemy = copymapscr.itemy;
4804 screens[screen].nextmap = copymapscr.nextmap;
4805 screens[screen].nextscr = copymapscr.nextscr;
4806 screens[screen].nocarry = copymapscr.nocarry;
4807 screens[screen].noreset = copymapscr.noreset;
4808 screens[screen].exstate_reset = copymapscr.exstate_reset;
4809 screens[screen].exstate_carry = copymapscr.exstate_carry;
4810 screens[screen].path[0] = copymapscr.path[0];
4811 screens[screen].path[1] = copymapscr.path[1];
4812 screens[screen].path[2] = copymapscr.path[2];
4813 screens[screen].path[3] = copymapscr.path[3];
4814 screens[screen].pattern = copymapscr.pattern;
4815 screens[screen].exitdir = copymapscr.exitdir;
4816 screens[screen].screen_midi = copymapscr.screen_midi;
4817 screens[screen].stairx = copymapscr.stairx;
4818 screens[screen].stairy = copymapscr.stairy;
4819 screens[screen].timedwarptics = copymapscr.timedwarptics;
4820 mark_save_dirty();
4821 }
4822 }
4823
4824 void zmap::PasteWarpLocations(const mapscr& copymapscr, int screen)
4825 {
4826 if(can_paste)
4827 {
4828 screens[screen].warpreturnc = copymapscr.warpreturnc;
4829 screens[screen].warparrivalx = copymapscr.warparrivalx;
4830 screens[screen].warparrivaly = copymapscr.warparrivaly;
4831
4832 for(int32_t i=0; i<4; i++)
4833 {
4834 screens[screen].warpreturnx[i] = copymapscr.warpreturnx[i];
4835 screens[screen].warpreturny[i] = copymapscr.warpreturny[i];
4836 }
4837
4838 mark_save_dirty();
4839 }
4840 }
4841
4842 void zmap::PasteDoors(const mapscr& copymapscr, int screen)
4843 {
4844 if(can_paste)
4845 {
4846 for(int32_t i=0; i<4; i++)
4847 screens[screen].door[i] = copymapscr.door[i];
4848
4849 screens[screen].door_combo_set = copymapscr.door_combo_set;
4850 mark_save_dirty();
4851 }
4852 }
4853
4854 void zmap::PasteLayers(const mapscr& copymapscr, int screen)
4855 {
4856 if(can_paste)
4857 {
4858 for(int32_t i=0; i<6; i++)
4859 {
4860 screens[screen].layermap[i] = copymapscr.layermap[i];
4861 screens[screen].layerscreen[i] = copymapscr.layerscreen[i];
4862 screens[screen].layeropacity[i] = copymapscr.layeropacity[i];
4863 }
4864
4865 mark_save_dirty();
4866 }
4867 }
4868
4869 void zmap::PasteRoom(const mapscr& copymapscr, int screen)
4870 {
4871 if(can_paste)
4872 {
4873 screens[screen].room = copymapscr.room;
4874 screens[screen].catchall = copymapscr.catchall;
4875 mark_save_dirty();
4876 }
4877 }
4878
4879 void zmap::PasteGuy(const mapscr& copymapscr, int screen)
4880 {
4881 if(can_paste)
4882 {
4883 screens[screen].guy = copymapscr.guy;
4884 screens[screen].guytile = copymapscr.guytile;
4885 screens[screen].guycs = copymapscr.guycs;
4886 SETFLAG(screens[screen].roomflags,RFL_ALWAYS_GUY,copymapscr.roomflags&RFL_ALWAYS_GUY);
4887 SETFLAG(screens[screen].roomflags,RFL_GUYFIRES,copymapscr.roomflags&RFL_GUYFIRES);
4888 screens[screen].str = copymapscr.str;
4889 mark_save_dirty();
4890 }
4891 }
4892
4893 void zmap::PastePalette(const mapscr& copymapscr, int screen)
4894 {
4895 if(can_paste)
4896 {
4897 screens[screen].color = copymapscr.color;
4898 screens[screen].valid|=mVALID;
4899 refresh_color();
4900
4901 mark_save_dirty();
4902 }
4903 }
4904
4905 void zmap::PasteAll(const mapscr& copymapscr, int screen)
4906 {
4907 if(can_paste)
4908 {
4909 copy_mapscr(&screens[screen], &copymapscr);
4910 zinit.screen_data[cursor.map*MAPSCRS+cursor.screen] = copyscrdata;
4911 screens[screen].valid|=mVALID;
4912
4913 refresh_color();
4914
4915 mark_save_dirty();
4916 }
4917 }
4918
4919
4920 void zmap::PasteToAll(const mapscr& copymapscr)
4921 {
4922 if(can_paste)
4923 {
4924 for(int32_t x=0; x<128; x++)
4925 {
4926 if(!(screens[x].valid&mVALID))
4927 {
4928 screens[x].valid |= mVALID;
4929 screens[x].color = copymapscr.color;
4930 }
4931
4932 for(int32_t i=0; i<176; i++)
4933 {
4934 screens[x].data[i] = copymapscr.data[i];
4935 screens[x].cset[i] = copymapscr.cset[i];
4936 screens[x].sflag[i] = copymapscr.sflag[i];
4937 }
4938 }
4939
4940 refresh_color();
4941
4942 mark_save_dirty();
4943 }
4944 }
4945
4946 void zmap::PasteAllToAll(const mapscr& copymapscr)
4947 {
4948 if(can_paste)
4949 {
4950 for(int32_t x=0; x<128; x++)
4951 {
4952 copy_mapscr(&screens[x], &copymapscr);
4953 zinit.screen_data[cursor.map*MAPSCRS+x] = copyscrdata;
4954 //screens[x]=copymapscr;
4955 }
4956
4957 refresh_color();
4958
4959 mark_save_dirty();
4960 }
4961 }
4962
4963 void zmap::PasteEnemies(const mapscr& copymapscr, int screen)
4964 {
4965 if(can_paste)
4966 {
4967 for(int32_t i=0; i<10; i++)
4968 screens[screen].enemy[i]=copymapscr.enemy[i];
4969 }
4970 }
4971
4972 bool zmap::CanGoBack() const
4973 {
4974 return !cursor_undo_stack.empty();
4975 }
4976
4977 bool zmap::CanGoForward() const
4978 {
4979 return !cursor_redo_stack.empty();
4980 }
4981
4982 void zmap::GoBack()
4983 {
4984 if (!CanGoBack())
4985 return;
4986
4987 cursor_redo_stack.push(cursor);
4988
4989 ConfigureCursorHistory(false);
4990 setCursor(cursor_undo_stack.back());
4991 ConfigureCursorHistory(true);
4992
4993 cursor_undo_stack.pop_back();
4994 }
4995
4996 void zmap::GoForward()
4997 {
4998 if (!CanGoForward())
4999 return;
5000
5001 cursor_undo_stack.push_back(cursor);
5002
5003 ConfigureCursorHistory(false);
5004 setCursor(cursor_redo_stack.top());
5005 ConfigureCursorHistory(true);
5006
5007 cursor_redo_stack.pop();
5008 }
5009
5010 void zmap::CapCursorHistory()
5011 {
5012 int max_history_size = 1000;
5013 while (cursor_undo_stack.size() > max_history_size)
5014 cursor_undo_stack.pop_front();
5015 }
5016
5017 void zmap::ConfigureCursorHistory(bool enable)
5018 {
5019 cursor_history_enabled = enable;
5020 }
5021
5022 void zmap::setCopyFFC(int32_t n)
5023 {
5024 copyffc = n;
5025 }
5026
5027 void zmap::update_combo_cycling()
5028 {
5029 if(!prv_mode||!prv_cmbcycle)
5030 {
5031 return;
5032 }
5033
5034 int32_t x;
5035 int32_t newdata[176];
5036 int32_t newcset[176];
5037 bool restartanim[MAXCOMBOS] = {0};
5038
5039 for(int32_t i=0; i<176; i++)
5040 {
5041 newdata[i]=-1;
5042 newcset[i]=-1;
5043
5044 x=prvscr.data[i];
5045
5046 //time to restart
5047 if((combobuf[x].aclk>=combobuf[x].speed) &&
5048 (combobuf[x].tile-combobuf[x].frames>=combobuf[x].o_tile-1) &&
5049 combobuf[x].can_cycle())
5050 {
5051 bool cycle_under = (combobuf[x].animflags & AF_CYCLEUNDERCOMBO);
5052 newdata[i] = cycle_under ? prvscr.undercombo : combobuf[x].nextcombo;
5053
5054 if(!(combobuf[x].animflags & AF_CYCLENOCSET))
5055 newcset[i] = cycle_under ? prvscr.undercset : combobuf[x].nextcset;
5056 int32_t c = newdata[i];
5057
5058 if(combobuf[c].animflags & AF_CYCLE)
5059 {
5060 restartanim[c]=true;
5061 }
5062 }
5063 }
5064
5065 for(int32_t i=0; i<176; i++)
5066 {
5067 x=prvscr.data[i];
5068
5069 //time to restart
5070 if((combobuf[x].aclk>=combobuf[x].speed) &&
5071 (combobuf[x].tile-combobuf[x].frames>=combobuf[x].o_tile-1) &&
5072 combobuf[x].can_cycle())
5073 {
5074 bool cycle_under = (combobuf[x].animflags & AF_CYCLEUNDERCOMBO);
5075 newdata[i] = cycle_under ? prvscr.undercombo : combobuf[x].nextcombo;
5076
5077 if(!(combobuf[x].animflags & AF_CYCLENOCSET))
5078 newcset[i] = cycle_under ? prvscr.undercset : combobuf[x].nextcset;
5079 int32_t c = newdata[i];
5080
5081 if(combobuf[c].animflags & AF_CYCLE)
5082 {
5083 restartanim[c]=true;
5084 }
5085 }
5086 }
5087
5088 for(int32_t i=0; i<176; i++)
5089 {
5090 if(newdata[i]==-1)
5091 continue;
5092
5093 prvscr.data[i]=newdata[i];
5094 prvscr.cset[i]=newcset[i];
5095 }
5096
5097 word maxffc = prvscr.numFFC();
5098 for(word i=0; i<maxffc; i++)
5099 {
5100 ffcdata& ffc = prvscr.ffcs[i];
5101 newcombo const& cmb = combobuf[ffc.data];
5102
5103 //time to restart
5104 if((cmb.aclk>=cmb.speed) &&
5105 (cmb.tile-cmb.frames>=cmb.o_tile-1) &&
5106 cmb.can_cycle())
5107 {
5108 bool cycle_under = (cmb.animflags & AF_CYCLEUNDERCOMBO);
5109 ffc.data = cycle_under ? prvscr.undercombo : cmb.nextcombo;
5110
5111 if(!(cmb.animflags & AF_CYCLENOCSET))
5112 newcset[i] = cycle_under ? prvscr.undercset : cmb.nextcset;
5113
5114 if(combobuf[ffc.data].animflags & AF_CYCLE)
5115 {
5116 restartanim[ffc.data]=true;
5117 }
5118 prvscr.ffcs[i].data = ffc.data;
5119 prvscr.ffcs[i].cset=ffc.cset;
5120 }
5121 }
5122
5123
5124 if(get_qr(qr_CMBCYCLELAYERS))
5125 {
5126 for(int32_t j=0; j<6; j++)
5127 {
5128 if(!prvlayers[j].valid)
5129 continue;
5130
5131 for(int32_t i=0; i<176; i++)
5132 {
5133 newdata[i]=-1;
5134 newcset[i]=-1;
5135
5136 x=(prvlayers[j]).data[i];
5137
5138 //time to restart
5139 if((combobuf[x].aclk>=combobuf[x].speed) &&
5140 (combobuf[x].tile-combobuf[x].frames>=combobuf[x].o_tile-1) &&
5141 combobuf[x].can_cycle())
5142 {
5143 bool cycle_under = (combobuf[x].animflags & AF_CYCLEUNDERCOMBO);
5144 newdata[i] = cycle_under ? prvscr.undercombo : combobuf[x].nextcombo;
5145
5146 if(!(combobuf[x].animflags & AF_CYCLENOCSET))
5147 newcset[i] = cycle_under ? prvscr.undercset : combobuf[x].nextcset;
5148 int32_t c = newdata[i];
5149
5150 if(combobuf[c].animflags & AF_CYCLE)
5151 {
5152 restartanim[c]=true;
5153 }
5154 }
5155 }
5156
5157 for(int32_t i=0; i<176; i++)
5158 {
5159 x=(prvlayers[j]).data[i];
5160
5161 //time to restart
5162 if((combobuf[x].aclk>=combobuf[x].speed) &&
5163 (combobuf[x].tile-combobuf[x].frames>=combobuf[x].o_tile-1) &&
5164 combobuf[x].can_cycle())
5165 {
5166 bool cycle_under = (combobuf[x].animflags & AF_CYCLEUNDERCOMBO);
5167 newdata[i] = cycle_under ? prvscr.undercombo : combobuf[x].nextcombo;
5168
5169 if(!(combobuf[x].animflags & AF_CYCLENOCSET))
5170 newcset[i] = cycle_under ? prvscr.undercset : combobuf[x].nextcset;
5171 int32_t c = newdata[i];
5172
5173 if(combobuf[c].animflags & AF_CYCLE)
5174 {
5175 restartanim[c]=true;
5176 }
5177 }
5178 }
5179
5180 for(int32_t i=0; i<176; i++)
5181 {
5182 if(newdata[i]==-1)
5183 continue;
5184
5185 prvlayers[j].data[i]=newdata[i];
5186 prvlayers[j].cset[i]=newcset[i];
5187 }
5188 }
5189 }
5190
5191 for(int32_t i=0; i<MAXCOMBOS; i++)
5192 {
5193 if(restartanim[i])
5194 {
5195 combobuf[i].tile = combobuf[i].o_tile;
5196 combobuf[i].cur_frame=0;
5197 combobuf[i].aclk = 0;
5198 }
5199 }
5200 }
5201
5202 void zmap::update_freeform_combos()
5203 {
5204 if(!prv_mode||!prv_cmbcycle)
5205 {
5206 return;
5207 }
5208
5209 // TODO: this changer code is a duplicated here and for zplayer. Should fix that.
5210 word maxffc = prvscr.numFFC();
5211 for(int32_t i=0; i<maxffc; i++)
5212 {
5213 if(!(prvscr.ffcs[i].flags&ffc_changer) && prvscr.ffcs[i].data!=0 && !(prvscr.ffcs[i].flags&ffc_stationary))
5214 {
5215 for(int32_t j=0; j<maxffc; j++)
5216 {
5217 if(i!=j)
5218 {
5219 if(prvscr.ffcs[j].flags&ffc_changer && prvscr.ffcs[j].data != 0)
5220 {
5221 if((((prvscr.ffcs[j].x.getInt())!=prvscr.ffcs[i].changer_x)||((prvscr.ffcs[j].y.getInt())!=prvscr.ffcs[i].changer_y))&&(prvscr.ffcs[i].link==0))
5222 {
5223 if((isonline(prvscr.ffcs[i].x.getZLong(),prvscr.ffcs[i].y.getZLong(),prvscr.ffcs[i].prev_changer_x,prvscr.ffcs[i].prev_changer_y,prvscr.ffcs[j].x.getZLong(),prvscr.ffcs[j].y.getZLong())||
5224 ((prvscr.ffcs[i].x.getZLong()==prvscr.ffcs[j].x.getZLong())&&(prvscr.ffcs[i].y.getZLong()==prvscr.ffcs[j].y.getZLong())))&&(prvscr.ffcs[i].prev_changer_x>-10000000&&prvscr.ffcs[i].prev_changer_y>-10000000))
5225 {
5226 //prvscr.ffcs[i].data=prvscr.ffcs[j].data;
5227 //prvscr.ffcs[i].cset=prvscr.ffcs[j].cset;
5228 if(prvscr.ffcs[j].flags&ffc_changethis)
5229 {
5230 prvscr.ffcs[i].data = prvscr.ffcs[j].data;
5231 prvscr.ffcs[i].cset = prvscr.ffcs[j].cset;
5232 }
5233
5234 if(prvscr.ffcs[j].flags&ffc_changenext)
5235 prvscr.ffcs[i].data += 1;
5236
5237 if(prvscr.ffcs[j].flags&ffc_changeprev)
5238 prvscr.ffcs[i].data -= 1;
5239
5240 prvscr.ffcs[i].delay=prvscr.ffcs[j].delay;
5241 prvscr.ffcs[i].x=prvscr.ffcs[j].x;
5242 prvscr.ffcs[i].y=prvscr.ffcs[j].y;
5243
5244 prvscr.ffcs[i].vx=prvscr.ffcs[j].vx;
5245 prvscr.ffcs[i].vy=prvscr.ffcs[j].vy;
5246 prvscr.ffcs[i].ax=prvscr.ffcs[j].ax;
5247 prvscr.ffcs[i].ay=prvscr.ffcs[j].ay;
5248
5249 prvscr.ffcs[i].link=prvscr.ffcs[j].link;
5250 prvscr.ffcs[i].hit_width=prvscr.ffcs[j].hit_width;
5251 prvscr.ffcs[i].hit_height=prvscr.ffcs[j].hit_height;
5252 prvscr.ffcs[i].txsz=prvscr.ffcs[j].txsz;
5253 prvscr.ffcs[i].tysz=prvscr.ffcs[j].tysz;
5254
5255 if(prvscr.ffcs[i].flags&ffc_carryover)
5256 prvscr.ffcs[i].flags=prvscr.ffcs[j].flags&ffc_carryover;
5257 else prvscr.ffcs[i].flags=prvscr.ffcs[j].flags;
5258
5259 prvscr.ffcs[i].flags&=~ffc_changer;
5260 prvscr.ffcs[i].changer_x=(prvscr.ffcs[j].x.getInt());
5261 prvscr.ffcs[i].changer_y=(prvscr.ffcs[j].y.getInt());
5262
5263 if(combobuf[prvscr.ffcs[j].data].flag>15 && combobuf[prvscr.ffcs[j].data].flag<32)
5264 {
5265 prvscr.ffcs[j].data = prvscr.secretcombo[combobuf[prvscr.ffcs[j].data].flag - 16 + 4];
5266 }
5267
5268 if((prvscr.ffcs[j].flags&ffc_swapnext)||(prvscr.ffcs[j].flags&ffc_swapprev))
5269 {
5270 int32_t k=0;
5271
5272 if(prvscr.ffcs[j].flags&ffc_swapnext)
5273 k=j<(MAXFFCS-1)?j+1:0;
5274
5275 if(prvscr.ffcs[j].flags&ffc_swapprev)
5276 k=j>0?j-1:(MAXFFCS-1);
5277
5278 zc_swap(prvscr.ffcs[j].vx,prvscr.ffcs[k].vx);
5279 zc_swap(prvscr.ffcs[j].vy,prvscr.ffcs[k].vy);
5280 zc_swap(prvscr.ffcs[j].ax,prvscr.ffcs[k].ax);
5281 zc_swap(prvscr.ffcs[j].ay,prvscr.ffcs[k].ay);
5282 zc_swap(prvscr.ffcs[j].link,prvscr.ffcs[k].link);
5283 zc_swap(prvscr.ffcs[j].hit_width,prvscr.ffcs[k].hit_width);
5284 zc_swap(prvscr.ffcs[j].hit_height,prvscr.ffcs[k].hit_height);
5285 zc_swap(prvscr.ffcs[j].txsz,prvscr.ffcs[k].txsz);
5286 zc_swap(prvscr.ffcs[j].tysz,prvscr.ffcs[k].tysz);
5287 zc_swap(prvscr.ffcs[j].flags,prvscr.ffcs[k].flags);
5288 }
5289 }
5290 }
5291 }
5292 }
5293 }
5294
5295 if(prvscr.ffcs[i].link ? !prvscr.ffcs[prvscr.ffcs[i].link].delay : !prvscr.ffcs[i].delay)
5296 {
5297 if(prvscr.ffcs[i].link&&(prvscr.ffcs[i].link-1)!=i)
5298 {
5299 prvscr.ffcs[i].prev_changer_x = prvscr.ffcs[i].x.getZLong();
5300 prvscr.ffcs[i].prev_changer_y = prvscr.ffcs[i].y.getZLong();
5301 prvscr.ffcs[i].x+=prvscr.ffcs[prvscr.ffcs[i].link-1].vx;
5302 prvscr.ffcs[i].y+=prvscr.ffcs[prvscr.ffcs[i].link-1].vy;
5303 }
5304 else
5305 {
5306 prvscr.ffcs[i].prev_changer_x = prvscr.ffcs[i].x.getZLong();
5307 prvscr.ffcs[i].prev_changer_y = prvscr.ffcs[i].y.getZLong();
5308 prvscr.ffcs[i].x+=prvscr.ffcs[i].vx;
5309 prvscr.ffcs[i].y+=prvscr.ffcs[i].vy;
5310 prvscr.ffcs[i].vx+=prvscr.ffcs[i].ax;
5311 prvscr.ffcs[i].vy+=prvscr.ffcs[i].ay;
5312
5313 if(get_qr(qr_OLD_FFC_SPEED_CAP))
5314 {
5315 if(prvscr.ffcs[i].vx>128) prvscr.ffcs[i].vx=128;
5316
5317 if(prvscr.ffcs[i].vx<-128) prvscr.ffcs[i].vx=-128;
5318
5319 if(prvscr.ffcs[i].vy>128) prvscr.ffcs[i].vy=128;
5320
5321 if(prvscr.ffcs[i].vy<-128) prvscr.ffcs[i].vy=-128;
5322 }
5323 }
5324 }
5325 else
5326 {
5327 if(!prvscr.ffcs[i].link || (prvscr.ffcs[i].link-1)==i)
5328 prvscr.ffcs[i].delay--;
5329 }
5330
5331 if(prvscr.ffcs[i].x<-32)
5332 {
5333 if(prvscr.flags6&fWRAPAROUNDFF)
5334 {
5335 prvscr.ffcs[i].x = (288+(prvscr.ffcs[i].x+32));
5336 prvscr.ffcs[i].prev_changer_y = prvscr.ffcs[i].y.getZLong();
5337 }
5338 else
5339 {
5340 prvscr.ffcs[i].data = 0;
5341 prvscr.ffcs[i].flags&=~ffc_carryover;
5342 }
5343 }
5344
5345 if(prvscr.ffcs[i].y<-32)
5346 {
5347 if(prvscr.flags6&fWRAPAROUNDFF)
5348 {
5349 prvscr.ffcs[i].y = 208+(prvscr.ffcs[i].y+32);
5350 prvscr.ffcs[i].prev_changer_x = prvscr.ffcs[i].x.getZLong();
5351 }
5352 else
5353 {
5354 prvscr.ffcs[i].data = 0;
5355 prvscr.ffcs[i].flags&=~ffc_carryover;
5356 }
5357 }
5358
5359 if(prvscr.ffcs[i].x>=288)
5360 {
5361 if(prvscr.flags6&fWRAPAROUNDFF)
5362 {
5363 prvscr.ffcs[i].x = prvscr.ffcs[i].x-288-32;
5364 prvscr.ffcs[i].prev_changer_y = prvscr.ffcs[i].y.getZLong();
5365 }
5366 else
5367 {
5368 prvscr.ffcs[i].data = 0;
5369 prvscr.ffcs[i].flags&=~ffc_carryover;
5370 }
5371 }
5372
5373 if(prvscr.ffcs[i].y>=208)
5374 {
5375 if(prvscr.flags6&fWRAPAROUNDFF)
5376 {
5377 prvscr.ffcs[i].y = prvscr.ffcs[i].y-208-32;
5378 prvscr.ffcs[i].prev_changer_y = prvscr.ffcs[i].x.getZLong();
5379 }
5380 else
5381 {
5382 prvscr.ffcs[i].data = 0;
5383 prvscr.ffcs[i].flags&=~ffc_carryover;
5384 }
5385 }
5386
5387 }
5388 }
5389 }
5390
5391 void zmap::goto_dmapscr(int dmap, int scr)
5392 {
5393 goto_mapscr(DMaps[dmap].map, scr);
5394 }
5395 void zmap::goto_mapscr(int map, int scr)
5396 {
5397 auto new_cursor = cursor;
5398 new_cursor.map = map;
5399 new_cursor.setScreen(scr);
5400 setCursor(std::move(new_cursor));
5401 }
5402
5403 void zmap::dowarp(int32_t type, int32_t index)
5404 {
5405 set_warpback();
5406 if(type==0)
5407 {
5408
5409 int32_t dmap=screens[cursor.screen].tilewarpdmap[index];
5410 int32_t scr=screens[cursor.screen].tilewarpscr[index];
5411
5412 switch(screens[cursor.screen].tilewarptype[index])
5413 {
5414 case wtCAVE:
5415 case wtNOWARP:
5416 break;
5417
5418 default:
5419 goto_dmapscr(dmap, scr);
5420 break;
5421 }
5422 }
5423 else if(type==1)
5424 {
5425 int32_t dmap=screens[cursor.screen].sidewarpdmap[index];
5426 int32_t scr=screens[cursor.screen].sidewarpscr[index];
5427
5428 switch(screens[cursor.screen].sidewarptype[index])
5429 {
5430 case wtCAVE:
5431 case wtNOWARP:
5432 break;
5433
5434 default:
5435 goto_dmapscr(dmap, scr);
5436 break;
5437 }
5438 }
5439 }
5440
5441 extern int32_t prv_twon;
5442
5443 void zmap::prv_dowarp(int32_t type, int32_t index)
5444 {
5445 if(type==0)
5446 {
5447
5448 int32_t dmap=prvscr.tilewarpdmap[index];
5449 int32_t scr=prvscr.tilewarpscr[index];
5450
5451 switch(prvscr.tilewarptype[index])
5452 {
5453 case wtCAVE:
5454 case wtNOWARP:
5455 break;
5456
5457 default:
5458 //setCurrMap(DMaps[dmap].map);
5459 //setCurrScr(scr+DMaps[dmap].xoff);
5460 set_prvscr(DMaps[dmap].map,scr+DMaps[dmap].xoff);
5461 refresh_color();
5462 //prv_cmbcycle=0;
5463 break;
5464 }
5465 }
5466 else if(type==1)
5467 {
5468 int32_t dmap=prvscr.sidewarpdmap[index];
5469 int32_t scr=prvscr.sidewarpscr[index];
5470
5471 switch(prvscr.sidewarptype[index])
5472 {
5473 case wtCAVE:
5474 case wtNOWARP:
5475 break;
5476
5477 default:
5478 //setCurrMap(DMaps[dmap].map);
5479 //setCurrScr(scr+DMaps[dmap].xoff);
5480 set_prvscr(DMaps[dmap].map,scr+DMaps[dmap].xoff);
5481 refresh_color();
5482 //prv_cmbcycle=0;
5483 break;
5484 }
5485 }
5486
5487 if(prv_twon)
5488 {
5489 prv_time=get_prvscr()->timedwarptics;
5490 }
5491 }
5492
5493 void zmap::dowarp2(int32_t ring,int32_t index)
5494 {
5495 set_warpback();
5496 goto_dmapscr(QMisc.warp[ring].dmap[index], QMisc.warp[ring].scr[index]);
5497 }
5498
5499 void zmap::set_warpback()
5500 {
5501 warpbackmap = cursor.map;
5502 warpbackscreen = cursor.screen;
5503 }
5504 bool zmap::has_warpback()
5505 {
5506 return warpbackmap && warpbackscreen
5507 && !(warpbackmap == cursor.map && warpbackscreen == cursor.screen);
5508 }
5509 void zmap::warpback()
5510 {
5511 if(!has_warpback())
5512 return;
5513
5514 int m = cursor.map, s = cursor.screen;
5515 goto_mapscr(*warpbackmap, *warpbackscreen);
5516 warpbackmap = m;
5517 warpbackscreen = s;
5518 }
5519
5520 bool save_msgstrs(const char *path)
5521 {
5522 PACKFILE *f = pack_fopen_password(path,F_WRITE, "");
5523
5524 if(!f)
5525 {
5526 return false;
5527 }
5528
5529 if(writestrings(f, ZELDA_VERSION, VERSION_BUILD, 0, MAXMSGS)==0)
5530 {
5531 pack_fclose(f);
5532 return true;
5533 }
5534
5535 pack_fclose(f);
5536 return false;
5537 }
5538
5539 1 bool save_strings_tsv(const char *path)
5540 {
5541 1 PACKFILE *f = pack_fopen_password(path,F_WRITE, "");
5542
5543
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if(!f)
5544 {
5545 return false;
5546 }
5547
5548
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if(writestrings_tsv(f)==0)
5549 {
5550 1 pack_fclose(f);
5551 1 return true;
5552 }
5553
5554 pack_fclose(f);
5555 return false;
5556 1 }
5557
5558 bool save_msgstrs_text(const char *path)
5559 {
5560 PACKFILE *f = pack_fopen_password(path,F_WRITE, "");
5561
5562 if(!f)
5563 {
5564 return false;
5565 }
5566
5567 if(writestrings_text(f)==0)
5568 {
5569 pack_fclose(f);
5570 return true;
5571 }
5572
5573 pack_fclose(f);
5574 return false;
5575 }
5576
5577 bool load_msgstrs(const char *path, int32_t startstring)
5578 {
5579 //these are here to bypass compiler warnings about unused arguments
5580 startstring=startstring;
5581
5582 dword section_id;
5583 PACKFILE *f = pack_fopen_password(path,F_READ, "");
5584
5585 if(!f)
5586 {
5587 return false;
5588 }
5589
5590 if(!p_mgetl(&section_id,f))
5591 {
5592 return false;
5593 }
5594
5595 if(section_id==ID_STRINGS)
5596 {
5597 if(readstrings(f, &header)==0)
5598 {
5599 pack_fclose(f);
5600 return true;
5601 }
5602 else
5603 {
5604 pack_fclose(f);
5605 return false;
5606 }
5607 }
5608
5609 pack_fclose(f);
5610 return false;
5611 }
5612
5613 bool load_strings_tsv(const char *path)
5614 {
5615 try
5616 {
5617 parse_strings_tsv(util::read_text_file(path));
5618 }
5619 catch (std::exception& ex)
5620 {
5621 InfoDialog("Import .tsv Error", ex.what()).show();
5622 return false;
5623 }
5624 return true;
5625 }
5626
5627 bool save_pals(const char *path)
5628 {
5629 PACKFILE *f = pack_fopen_password(path,F_WRITE, "");
5630
5631 if(!f)
5632 {
5633 return false;
5634 }
5635
5636 if(writecolordata(f, ZELDA_VERSION, VERSION_BUILD, 0, newerpdTOTAL)==0)
5637 {
5638 pack_fclose(f);
5639 return true;
5640 }
5641
5642 pack_fclose(f);
5643 return false;
5644 }
5645
5646 bool load_pals(const char *path, int32_t startcset)
5647 {
5648 dword section_id;
5649 PACKFILE *f = pack_fopen_password(path,F_READ, "");
5650
5651 if(!f)
5652 {
5653 return false;
5654 }
5655
5656 if(!p_mgetl(&section_id,f))
5657 {
5658 return false;
5659 }
5660
5661 if(section_id==ID_CSETS)
5662 {
5663 if(readcolordata(f, &QMisc, 0x250, 33, startcset, newerpdTOTAL-startcset)==0)
5664 {
5665 pack_fclose(f);
5666 loadlvlpal(Color);
5667 return true;
5668 }
5669 else
5670 {
5671 pack_fclose(f);
5672 return false;
5673 }
5674 }
5675
5676 return false;
5677 }
5678
5679 int32_t writeguys(PACKFILE *f, zquestheader *Header);
5680 bool save_guys(const char *path)
5681 {
5682 PACKFILE *f = pack_fopen_password(path,F_WRITE, "");
5683
5684 if(!f)
5685 {
5686 return false;
5687 }
5688
5689 /*
5690 int32_t id = ID_GUYS;
5691 if(!p_mputl(id,f))
5692 {
5693 return false;
5694 }
5695 */
5696
5697 zquestheader h;
5698 h.zelda_version = 0x250;
5699 h.build = 21;
5700
5701 if(writeguys(f, &h)==0)
5702 {
5703 pack_fclose(f);
5704 return true;
5705 }
5706
5707 pack_fclose(f);
5708 return false;
5709 }
5710
5711 bool load_guys(const char *path)
5712 {
5713 dword section_id;
5714 PACKFILE *f = pack_fopen_password(path,F_READ, "");
5715
5716 if(!f)
5717 {
5718 return false;
5719 }
5720
5721 if(!p_mgetl(&section_id,f))
5722 {
5723 pack_fclose(f);
5724 return false;
5725 }
5726
5727 zquestheader h;
5728 h.zelda_version = 0x250;
5729 h.build = 21;
5730
5731 if(section_id==ID_GUYS)
5732 {
5733 if(readguys(f, &h)==0)
5734 {
5735 pack_fclose(f);
5736 return true;
5737 }
5738 }
5739
5740 pack_fclose(f);
5741 return false;
5742 }
5743
5744
5745 //int32_t writeguys(PACKFILE *f, zquestheader *Header);
5746 bool save_combo_alias(const char *path)
5747 {
5748 PACKFILE *f = pack_fopen_password(path,F_WRITE, "");
5749
5750 if(!f)
5751 {
5752 return false;
5753 }
5754
5755 zquestheader h;
5756 h.zelda_version = 0x250;
5757 h.build = 21;
5758
5759 if(writecomboaliases(f, 0, 0)==0)
5760 {
5761 pack_fclose(f);
5762 return true;
5763 }
5764
5765 pack_fclose(f);
5766 return false;
5767 }
5768
5769 bool load_combo_alias(const char *path)
5770 {
5771 dword section_id;
5772 PACKFILE *f = pack_fopen_password(path,F_READ, "");
5773
5774 if(!f)
5775 {
5776 return false;
5777 }
5778
5779 if(!p_mgetl(&section_id,f))
5780 {
5781 pack_fclose(f);
5782 return false;
5783 }
5784
5785 zquestheader h;
5786 h.zelda_version = 0x250;
5787 h.build = 21;
5788
5789 if(section_id==ID_COMBOALIASES)
5790 {
5791 if(readcomboaliases(f, &h, 0, 0)==0)
5792 {
5793 pack_fclose(f);
5794 return true;
5795 }
5796 }
5797
5798 pack_fclose(f);
5799 return false;
5800 }
5801
5802 bool load_zgp(const char *path)
5803 {
5804 dword section_id;
5805 word section_version;
5806 PACKFILE *f=pack_fopen_password(path,F_READ,"");
5807
5808 if(!f)
5809 return false;
5810
5811 if(!p_mgetl(&section_id,f))
5812 {
5813 pack_fclose(f);
5814 return false;
5815 }
5816
5817 if(section_id!=ID_GRAPHICSPACK)
5818 {
5819 pack_fclose(f);
5820 return false;
5821 }
5822
5823 //section version info
5824 if(!p_igetw(&section_version,f))
5825 {
5826 return 2;
5827 }
5828
5829 if(!read_deprecated_section_cversion(f))
5830 {
5831 return 3;
5832 }
5833
5834 //tiles
5835 if(!p_mgetl(&section_id,f))
5836 {
5837 pack_fclose(f);
5838 return false;
5839 }
5840
5841 if(section_id==ID_TILES)
5842 {
5843 if(readtiles(f, newtilebuf, NULL, ZELDA_VERSION, VERSION_BUILD, 0, NEWMAXTILES, false)!=0)
5844 {
5845 pack_fclose(f);
5846 init_tiles(true, &header);
5847 return false;
5848 }
5849 }
5850 else
5851 {
5852 pack_fclose(f);
5853 return false;
5854 }
5855
5856 //combos
5857 if(!p_mgetl(&section_id,f))
5858 {
5859 pack_fclose(f);
5860 return false;
5861 }
5862
5863 if(section_id==ID_COMBOS)
5864 {
5865 if(readcombos(f, NULL, ZELDA_VERSION, VERSION_BUILD, 0, MAXCOMBOS)!=0)
5866 {
5867 pack_fclose(f);
5868 return false;
5869 }
5870 }
5871 else
5872 {
5873 pack_fclose(f);
5874 return false;
5875 }
5876
5877 //palettes
5878 if(!p_mgetl(&section_id,f))
5879 {
5880 pack_fclose(f);
5881 return false;
5882 }
5883
5884 if(section_id==ID_CSETS)
5885 {
5886 if(readcolordata(f, &QMisc, ZELDA_VERSION, VERSION_BUILD, 0, newerpdTOTAL)!=0)
5887 {
5888 pack_fclose(f);
5889 return false;
5890 }
5891 }
5892 else
5893 {
5894 pack_fclose(f);
5895 return false;
5896 }
5897
5898 //items
5899 if(!p_mgetl(&section_id,f))
5900 {
5901 pack_fclose(f);
5902 return false;
5903 }
5904
5905 if(section_id==ID_ITEMS)
5906 {
5907 if(readitems(f, ZELDA_VERSION, VERSION_BUILD)!=0)
5908 {
5909 pack_fclose(f);
5910 return false;
5911 }
5912 }
5913 else
5914 {
5915 pack_fclose(f);
5916 return false;
5917 }
5918
5919 //weapons
5920 if(!p_mgetl(&section_id,f))
5921 {
5922 pack_fclose(f);
5923 return false;
5924 }
5925
5926 if(section_id==ID_WEAPONS)
5927 {
5928 if(readweapons(f, &header)!=0)
5929 {
5930 pack_fclose(f);
5931 return false;
5932 }
5933 }
5934 else
5935 {
5936 pack_fclose(f);
5937 return false;
5938 }
5939
5940 //read the triforce pieces info and make sure it worked
5941 //really do this?
5942
5943 //read the game icons info and make sure it worked
5944 if(!p_mgetl(&section_id,f))
5945 {
5946 pack_fclose(f);
5947 return false;
5948 }
5949
5950 if(section_id==ID_ICONS)
5951 {
5952 if(readgameicons(f, &header, &QMisc)!=0)
5953 {
5954 pack_fclose(f);
5955 return false;
5956 }
5957 }
5958 else
5959 {
5960 pack_fclose(f);
5961 return false;
5962 }
5963
5964 //read the misc colors info and map styles info and make sure it worked
5965 if(!p_mgetl(&section_id,f))
5966 {
5967 pack_fclose(f);
5968 return false;
5969 }
5970
5971 if(section_id==ID_COLORS)
5972 {
5973 if(readmisccolors(f, &header, &QMisc)!=0)
5974 {
5975 pack_fclose(f);
5976 return false;
5977 }
5978 }
5979 else
5980 {
5981 pack_fclose(f);
5982 return false;
5983 }
5984
5985 //read the door combo sets and make sure it worked
5986 if(!p_mgetl(&section_id,f))
5987 {
5988 pack_fclose(f);
5989 return false;
5990 }
5991
5992 if(section_id==ID_DOORS)
5993 {
5994 if(readdoorcombosets(f, &header)!=0)
5995 {
5996 pack_fclose(f);
5997 return false;
5998 }
5999 }
6000 else
6001 {
6002 pack_fclose(f);
6003 return false;
6004 }
6005
6006 //read the template screens and make sure it worked
6007 //really do this?
6008
6009 //yay! it worked! close the file and say everything was ok.
6010 loadlvlpal(Color);
6011 setup_combo_animations();
6012 setup_combo_animations2();
6013 pack_fclose(f);
6014 return true;
6015 }
6016
6017 bool save_zgp(const char *path)
6018 {
6019 reset_combo_animations();
6020 reset_combo_animations2();
6021
6022 //open the file
6023 PACKFILE *f=pack_fopen_password(path,F_WRITE, "");
6024
6025 if(!f)
6026 return false;
6027
6028 dword section_id=ID_GRAPHICSPACK;
6029 dword section_version=V_GRAPHICSPACK;
6030
6031 //section id
6032 if(!p_mputl(section_id,f))
6033 {
6034 return 1;
6035 }
6036
6037 //section version info
6038 if(!p_iputw(section_version,f))
6039 {
6040 return 2;
6041 }
6042
6043 if(!write_deprecated_section_cversion(section_version,f))
6044 {
6045 return 3;
6046 }
6047
6048 //tiles
6049 if(writetiles(f, ZELDA_VERSION, VERSION_BUILD, 0, NEWMAXTILES)!=0)
6050 {
6051 pack_fclose(f);
6052 return false;
6053 }
6054
6055 //combos
6056 if(writecombos(f, ZELDA_VERSION, VERSION_BUILD, 0, MAXCOMBOS)!=0)
6057 {
6058 pack_fclose(f);
6059 return false;
6060 }
6061
6062 //palettes
6063 if(writecolordata(f, ZELDA_VERSION, VERSION_BUILD, 0, newerpdTOTAL)!=0)
6064 {
6065 pack_fclose(f);
6066 return false;
6067 }
6068
6069 //items
6070 if(writeitems(f, &header)!=0)
6071 {
6072 pack_fclose(f);
6073 return false;
6074 }
6075
6076 //weapons
6077 if(writeweapons(f, &header)!=0)
6078 {
6079 pack_fclose(f);
6080 return false;
6081 }
6082
6083 //write the triforce pieces info and make sure it worked
6084 //really do this?
6085
6086 //write the game icons info and make sure it worked
6087 if(writegameicons(f, &header)!=0)
6088 {
6089 pack_fclose(f);
6090 return false;
6091 }
6092
6093 //write the misc colors info and map styles info and make sure it worked
6094 if(writemisccolors(f, &header)!=0)
6095 {
6096 pack_fclose(f);
6097 return false;
6098 }
6099
6100 //write the door combo sets and make sure it worked
6101 if(writedoorcombosets(f, &header)!=0)
6102 {
6103 pack_fclose(f);
6104 return false;
6105 }
6106
6107 //write the template screens and make sure it worked
6108 //really do this?
6109
6110 pack_fclose(f);
6111 return true;
6112 }
6113
6114 bool save_subscreen(const char *path, ZCSubscreen const& savefrom)
6115 {
6116 //open the file
6117 PACKFILE *f=pack_fopen_password(path,F_WRITE, "");
6118
6119 if(!f)
6120 return false;
6121
6122 dword section_id=ID_SUBSCREEN;
6123 dword s_version=V_SUBSCREEN;
6124
6125 if(!p_mputl(section_id,f))
6126 {
6127 pack_fclose(f);
6128 return false;
6129 }
6130
6131 if(!p_iputw(s_version,f))
6132 {
6133 pack_fclose(f);
6134 return false;
6135 }
6136
6137 if(!write_deprecated_section_cversion(s_version,f))
6138 {
6139 pack_fclose(f);
6140 return false;
6141 }
6142
6143 if(savefrom.write(f))
6144 {
6145 pack_fclose(f);
6146 return false;
6147 }
6148
6149 pack_fclose(f);
6150 return true;
6151 }
6152
6153 bool load_subscreen(const char *path, ZCSubscreen& loadto)
6154 {
6155 //open the file
6156 PACKFILE *f=pack_fopen_password(path,F_READ, "");
6157
6158 if(!f)
6159 return false;
6160
6161 dword section_id;
6162 dword s_version;
6163
6164 if(!p_mgetl(&section_id,f))
6165 {
6166 pack_fclose(f);
6167 return false;
6168 }
6169
6170 if(section_id!=ID_SUBSCREEN)
6171 {
6172 pack_fclose(f);
6173 return false;
6174 }
6175
6176 if(!p_igetw(&s_version,f))
6177 {
6178 pack_fclose(f);
6179 return false;
6180 }
6181
6182 if (s_version > V_SUBSCREEN)
6183 return qe_version;
6184
6185 if(!read_deprecated_section_cversion(f))
6186 {
6187 pack_fclose(f);
6188 return false;
6189 }
6190
6191 if(s_version < 8)
6192 {
6193 subscreen_group g;
6194 memset(&g,0,sizeof(subscreen_group));
6195 if(read_one_old_subscreen(f,&g,s_version)!=0)
6196 {
6197 pack_fclose(f);
6198 return false;
6199 }
6200 if(g.ss_type != loadto.sub_type)
6201 {
6202 pack_fclose(f);
6203 displayinfo("Failure!",fmt::format("Found subscreen type '{}', expecting type '{}'",
6204 subscr_names[g.ss_type], subscr_names[loadto.sub_type]));
6205 return false;
6206 }
6207 loadto.clear();
6208 if(g.objects[0].type != ssoNULL)
6209 loadto.load_old(g);
6210 }
6211 else
6212 {
6213 ZCSubscreen tmp = ZCSubscreen();
6214 if (tmp.read(f, s_version))
6215 {
6216 pack_fclose(f);
6217 return false;
6218 }
6219 if(tmp.sub_type != loadto.sub_type)
6220 {
6221 pack_fclose(f);
6222 displayinfo("Failure!",fmt::format("Found subscreen type '{}', expecting type '{}'",
6223 subscr_names[tmp.sub_type], subscr_names[loadto.sub_type]));
6224 return false;
6225 }
6226 loadto.clear();
6227 loadto = tmp;
6228 }
6229
6230 pack_fclose(f);
6231 return true;
6232 }
6233
6234 bool setMapCount2(int32_t c)
6235 {
6236 int32_t oldmapcount=map_count;
6237 int32_t cur_map=Map.getCurrMap();
6238
6239 bound(c,1,MAXMAPS);
6240 map_count=c;
6241
6242 try
6243 {
6244 TheMaps.resize(c*MAPSCRS);
6245 Map.force_refr_pointer();
6246 map_infos.resize(c);
6247 }
6248 catch(...)
6249 {
6250 jwin_alert("Error","Failed to change map count.",NULL,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
6251 return false;
6252 }
6253
6254 bound(cur_map,0,c-1);
6255 if(map_count>oldmapcount)
6256 {
6257 for(int32_t mc=oldmapcount; mc<map_count; mc++)
6258 {
6259 // copy the default palette to the new maps
6260 map_infos[mc].autopalette = map_infos[cur_map].autopalette;
6261
6262 Map.setCurrMap(mc);
6263 for(int32_t ms=0; ms<MAPSCRS; ms++)
6264 Map.clearscr(ms);
6265 }
6266 Map.setCurrMap(cur_map);
6267 }
6268 else
6269 {
6270 Map.setCurrMap(cur_map);
6271 if(!layers_valid(Map.CurrScr()))
6272 fix_layers(Map.CurrScr(), false);
6273
6274 for(int32_t i=0; i<MAXDMAPS; i++)
6275 {
6276 if(DMaps[i].map>=map_count)
6277 {
6278 DMaps[i].map=map_count-1;
6279 }
6280 }
6281 }
6282
6283 return true;
6284 }
6285
6286 extern BITMAP *bmap;
6287
6288 static bool loading_file_new = false;
6289 int32_t init_quest(std::string tileset_path)
6290 {
6291 if (tileset_path.empty())
6292 tileset_path = DEFAULT_TILESET;
6293
6294 loading_file_new = true;
6295 load_quest(tileset_path.c_str());
6296 loading_file_new = false;
6297
6298 set_window_title("ZC Editor - Untitled Quest");
6299 zinit.last_map = 0;
6300 zinit.last_screen = 0;
6301
6302 if(bmap != NULL)
6303 {
6304 destroy_bitmap(bmap);
6305 bmap=NULL;
6306 }
6307
6308 return 0;
6309 }
6310
6311 void set_questpwd(std::string_view pwd, bool use_keyfile)
6312 {
6313 header.use_keyfile=use_keyfile;
6314
6315 // string_view actually has some quirks that make it less than ideal here.
6316 // It'd probably be best to replace it, but this works for now.
6317 memset(header.password, 0, 256);
6318 strcpy(header.password, pwd.data());
6319 header.dirty_password=true;
6320
6321 cvs_MD5Context ctx;
6322 cvs_MD5Init(&ctx);
6323 cvs_MD5Update(&ctx, (const uint8_t*)header.password, strlen(header.password));
6324 cvs_MD5Final(header.pwd_hash, &ctx);
6325 }
6326
6327
6328 bool is_null_pwd_hash(uint8_t *pwd_hash)
6329 {
6330 cvs_MD5Context ctx;
6331 uint8_t md5sum[16];
6332 char pwd[2]="";
6333
6334 cvs_MD5Init(&ctx);
6335 cvs_MD5Update(&ctx, (const uint8_t*)pwd, (unsigned)strlen(pwd));
6336 cvs_MD5Final(md5sum, &ctx);
6337
6338 return (memcmp(md5sum,pwd_hash,16)==0);
6339 }
6340
6341 static DIALOG pwd_dlg[] =
6342 {
6343 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) */
6344 { jwin_win_proc, 0, 0, 224+22+1, 88+10+1, vc(14), vc(1), 0, 0, 0, 0, (void *) "Requires Authorization", NULL, NULL },
6345 { jwin_text_proc, 16, 28, 96, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "File name:", NULL, NULL },
6346 // 2 (filename)
6347 { jwin_text_proc, 72, 28, 128, 8, vc(11), vc(1), 0, 0, 24, 0, NULL, NULL, NULL },
6348 { jwin_text_proc, 16, 38, 0, 8, vc(15), vc(1), 0, 0, 0, 0, (void *) "Challenge:", NULL, NULL },
6349 // 4 (challenge hash)
6350 { jwin_text_proc, 72, 38, 0, 8, vc(15), vc(1), 0, 0, 0, 0, NULL, NULL, NULL },
6351 { jwin_text_proc, 16, 42+10, 96, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Password:", NULL, NULL },
6352 // 6 (password)
6353 { jwin_edit_proc, 72, 38+10, 120+39, 16, vc(12), vc(1), 0, 0, 255, 0, NULL, NULL, NULL },
6354 { jwin_button_proc, 42, 62+10, 61, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
6355 { jwin_button_proc, 122, 62+10, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
6356 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
6357 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
6358 };
6359
6360 int32_t reverse_string(char* str)
6361 {
6362
6363 if(NULL==str)
6364 {
6365 return -1; //no string
6366 }
6367
6368 int32_t l=(int32_t)strlen(str)-1; //get the string length
6369
6370 if(1==l)
6371 {
6372 return 1;
6373 }
6374
6375 char c;
6376
6377 for(int32_t x=0; x < l; x++,l--)
6378 {
6379 c = str[x];
6380 str[x] = str[l];
6381 str[l] = c;
6382 }
6383
6384 return 0;
6385 }
6386
6387 #ifdef __GNUC__
6388 #pragma GCC diagnostic push
6389 #pragma GCC diagnostic ignored "-Wunreachable-code"
6390 #endif
6391
6392 11 int32_t quest_access(const char *filename, zquestheader *hdr)
6393 {
6394
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 if (is_headless())
6395 11 return 1;
6396
6397 #ifdef __EMSCRIPTEN__
6398 return 1;
6399 #endif
6400
6401 //Protection against compiling a release version with password protection off.
6402 static bool passguard = false;
6403
6404 #if ( !(defined _DEBUG) || (defined _RELEASE || defined NDEBUG || defined _NDEBUG) )
6405 #define MUST_HAVE_PASSWORD
6406 passguard = true;
6407 #endif
6408
6409 #if ( !(defined MUST_HAVE_PASSWORD) || defined _NPASS )
6410 #if (defined _MSC_VER || defined _NPASS)
6411 return 1;
6412 #endif
6413 #endif
6414 if(devpwd()) return 1;
6415
6416 char hash_string[33];
6417
6418 if((get_debug() && (!(CHECK_CTRL_CMD))) || is_null_pwd_hash(hdr->pwd_hash))
6419 {
6420 return 1;
6421 }
6422
6423 if(check_keyfiles(filename, {KEYFILE_MASTER,KEYFILE_ZPWD}, hdr))
6424 return true;
6425
6426 pwd_dlg[0].dp2=get_zc_font(font_lfont);
6427 pwd_dlg[2].dp=get_filename(filename);
6428 cvs_MD5Context ctx;
6429 uint8_t md5sum[16]={0};
6430 char response[33]="";
6431 char prompt[256]="";
6432
6433 memcpy(md5sum, hdr->pwd_hash, 16);
6434
6435 for(int32_t i=0; i<300; ++i)
6436 {
6437 for(int32_t j=0; j<16; ++j)
6438 {
6439 sprintf(response+j*2, "%02x", md5sum[j]);
6440 }
6441
6442 if(i&1)
6443 {
6444 reverse_string(response);
6445 }
6446
6447 if(i==149)
6448 {
6449 strcpy(hash_string, response);
6450 }
6451
6452 cvs_MD5Init(&ctx);
6453 cvs_MD5Update(&ctx, (const uint8_t*)response, (unsigned)strlen(response));
6454 cvs_MD5Final(md5sum, &ctx);
6455 }
6456
6457 pwd_dlg[4].dp=hash_string;
6458
6459 if(get_debug() && (CHECK_CTRL_CMD)) //...what is this doing?
6460 {
6461 sprintf(prompt,"%s",response);
6462 }
6463
6464 pwd_dlg[6].dp=prompt;
6465
6466 large_dialog(pwd_dlg);
6467
6468 int32_t cancel = do_zqdialog(pwd_dlg,6);
6469
6470 if(cancel == 8)
6471 return 2;
6472
6473 bool ret=check_questpwd(hdr, prompt);
6474
6475 if(!ret)
6476 {
6477 ret=(strcmp(response,prompt)==0);
6478 }
6479 return ret ? 1 : 0;
6480 11 }
6481
6482 void set_rules(byte* newrules);
6483 11 void popup_bugfix_dlg(const char* cfg, byte* dest_qrs)
6484 {
6485 11 bool dont_show_again = zc_get_config("zquest",cfg,0);
6486
2/4
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 11 times.
11 if(!dont_show_again && hasCompatRulesEnabled())
6487 {
6488
2/4
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 11 times.
✗ Branch 3 not taken.
33 AlertDialog("Apply New Bugfixes",
6489
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 "New bugfixes found that can be applied to this quest!"
6490 "\nWould you like to apply them?"
6491 "\n(Applies 'Bugfix' rule template, un-checking compat rules)",
6492 11 [&](bool ret,bool dsa)
6493 {
6494 if(ret)
6495 {
6496 applyRuleTemplate(ruletemplateFixCompat,dest_qrs);
6497 }
6498 if(dsa)
6499 {
6500 zc_set_config("zquest",cfg,1);
6501 }
6502 },
6503
2/4
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 11 times.
✗ Branch 3 not taken.
11 "Yes","No",
6504 0,false, //timeout - none
6505 true //"Don't show this again"
6506
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
11 ).show();
6507 11 }
6508 11 }
6509
6510 #ifdef __GNUC__
6511 #pragma GCC diagnostic pop
6512 #endif
6513
6514 11 int32_t load_quest(const char *filename, bool show_progress)
6515 {
6516 11 zq_freeze_all_rti();
6517
6518 char buf[2048];
6519 byte skip_flags[4];
6520
6521 11 dword tileset_flags = 0;
6522
2/2
✓ Branch 0 taken 44 times.
✓ Branch 1 taken 11 times.
55 for(int32_t i=0; i<4; ++i)
6523 {
6524 44 skip_flags[i]=0;
6525 44 }
6526
2/2
✓ Branch 0 taken 7634 times.
✓ Branch 1 taken 11 times.
7645 for(int32_t i=0; i<qr_MAX; i++)
6527 7634 set_qr(i,0);
6528 11 int32_t ret=loadquest(filename,&header,&QMisc,customtunes,show_progress,skip_flags,1,true,0,tileset_flags);
6529
6530
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
11 if(ret!=qe_OK)
6531 {
6532 init_quest(DEFAULT_TILESET);
6533 }
6534 else
6535 {
6536 11 int32_t accessret = quest_access(filename, &header);
6537
6538
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
11 if(accessret != 1)
6539 {
6540 init_quest(DEFAULT_TILESET);
6541
6542 if(accessret == 0)
6543 ret=qe_pwd;
6544 else
6545 ret=qe_cancel;
6546 }
6547 else
6548 {
6549 11 Map.clear();
6550
6551
2/4
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 11 times.
✗ Branch 3 not taken.
11 std::string qst_cfg_header = qst_cfg_header_from_path(filename);
6552
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 int view_size = zc_get_config(qst_cfg_header.c_str(), "zoom_num_screens", 1);
6553
6554
4/8
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 11 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 11 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 11 times.
✗ Branch 7 not taken.
11 Map.setCursor(MapCursor{
6555
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 .map = vbound(zinit.last_map, 0, map_count - 1),
6556 11 .screen = zinit.last_screen,
6557 11 .viewscr = zinit.last_screen,
6558 11 .size = view_size,
6559 });
6560
6561 extern int32_t current_mappage;
6562 11 current_mappage = 0;
6563 11 bool found_default = false;
6564
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 83 times.
92 for(int q = 0; q < MAX_MAPPAGE_BTNS; ++q)
6565 {
6566 83 auto &pg = map_page[q];
6567
4/4
✓ Branch 0 taken 11 times.
✓ Branch 1 taken 72 times.
✓ Branch 2 taken 9 times.
✓ Branch 3 taken 2 times.
83 if(pg.map == Map.getCurrMap() && pg.screen == Map.getCurrScr())
6568 {
6569 2 current_mappage = q;
6570 2 break;
6571 }
6572
4/8
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 72 times.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 9 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
81 else if(found_default || pg.map > 1 || (pg.map == 1 && pg.screen > 0))
6573 72 continue;
6574 else
6575 {
6576 9 current_mappage = q;
6577 9 found_default = true;
6578 }
6579 9 }
6580
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 refresh(rALL);
6581
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 refresh_pal();
6582
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 set_rules(quest_rules);
6583 11 saved = true;
6584
1/6
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
11 if(!(loading_file_new && zc_get_config("zquest","auto_filenew_bugfixes",1)))
6585
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 popup_bugfix_dlg("dsa_compatrule",nullptr);
6586
6587
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
11 if(bmap != NULL)
6588 {
6589 destroy_bitmap(bmap);
6590 bmap=NULL;
6591 }
6592
6593
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
11 if (show_progress)
6594 {
6595 sprintf(buf,"ZC Editor - [%s]", get_filename(filename));
6596 set_window_title(buf);
6597 }
6598 11 }
6599 }
6600
6601 11 Map.ClearCommandHistory();
6602
6603
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 if (!is_headless())
6604 {
6605 void load_size_poses();
6606 load_size_poses();
6607 }
6608
6609 11 return ret;
6610 }
6611
6612 int32_t load_tileset(const char *filename, dword tsetflags)
6613 {
6614 zq_freeze_all_rti();
6615
6616 byte skip_flags[4];
6617
6618 for(int32_t i=0; i<4; ++i)
6619 skip_flags[i]=0;
6620 for(int32_t i=0; i<qr_MAX; i++)
6621 set_qr(i,0);
6622 int32_t ret=loadquest(filename,&header,&QMisc,customtunes,true,skip_flags,1,true,0,tsetflags);
6623
6624 if(ret!=qe_OK)
6625 init_quest(DEFAULT_TILESET);
6626 else
6627 {
6628 if(tsetflags & TILESET_BUGFIX)
6629 applyRuleTemplate(ruletemplateFixCompat);
6630 if(tsetflags & TILESET_SCR_BUGFIX)
6631 applyRuleTemplate(ruletemplateFixZSCompat);
6632
6633 int32_t accessret = quest_access(filename, &header);
6634
6635 if(accessret != 1)
6636 {
6637 init_quest(DEFAULT_TILESET);
6638
6639 if(accessret == 0)
6640 ret=qe_pwd;
6641 else
6642 ret=qe_cancel;
6643 }
6644 else
6645 {
6646 Map.clear();
6647 Map.setCurrMap(vbound(zinit.last_map,0,map_count-1));
6648 Map.setCurrScr(zinit.last_screen);
6649 extern int32_t current_mappage;
6650 current_mappage = 0;
6651 bool found_default = false;
6652 for(int q = 0; q < MAX_MAPPAGE_BTNS; ++q)
6653 {
6654 auto &pg = map_page[q];
6655 if(pg.map == Map.getCurrMap() && pg.screen == Map.getCurrScr())
6656 {
6657 current_mappage = q;
6658 break;
6659 }
6660 else if(found_default || pg.map > 1 || (pg.map == 1 && pg.screen > 0))
6661 continue;
6662 else
6663 {
6664 current_mappage = q;
6665 found_default = true;
6666 }
6667 }
6668 refresh(rALL);
6669 refresh_pal();
6670 set_rules(quest_rules);
6671
6672 if(bmap != NULL)
6673 {
6674 destroy_bitmap(bmap);
6675 bmap=NULL;
6676 }
6677
6678 set_window_title("ZC Editor - Untitled Quest");
6679 first_save = false;
6680 mark_save_dirty();
6681 memset(filepath,0,255);
6682 memset(temppath,0,255);
6683 }
6684 }
6685
6686 Map.ClearCommandHistory();
6687
6688 return ret;
6689 }
6690
6691 272730 int32_t write_weap_data(weapon_data const& data, PACKFILE* f)
6692 {
6693
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if(!p_iputw(V_WEAP_DATA,f))
6694 new_return(1);
6695
6696
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputw(data.flags, f))
6697 new_return(2);
6698
6699
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputl(data.moveflags, f))
6700 new_return(3);
6701
6702
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputw(data.wflags, f))
6703 new_return(4);
6704
6705
2/2
✓ Branch 0 taken 1363650 times.
✓ Branch 1 taken 272730 times.
1636380 for (int32_t q = 0; q < WPNSPR_MAX; ++q)
6706 {
6707
1/2
✓ Branch 0 taken 1363650 times.
✗ Branch 1 not taken.
1363650 if (!p_putc(data.burnsprs[q], f))
6708 new_return(5);
6709
1/2
✓ Branch 0 taken 1363650 times.
✗ Branch 1 not taken.
1363650 if (!p_putc(data.light_rads[q], f))
6710 new_return(6);
6711 1363650 }
6712
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_putc(data.glow_shape, f))
6713 new_return(7);
6714
6715
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputl(data.override_flags, f))
6716 new_return(8);
6717
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputl(data.tilew, f))
6718 new_return(9);
6719
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputl(data.tileh, f))
6720 new_return(10);
6721
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputl(data.hxsz, f))
6722 new_return(11);
6723
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputl(data.hysz, f))
6724 new_return(12);
6725
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputl(data.hzsz, f))
6726 new_return(13);
6727
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputl(data.hxofs, f))
6728 new_return(14);
6729
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputl(data.hyofs, f))
6730 new_return(15);
6731
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputl(data.xofs, f))
6732 new_return(16);
6733
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputl(data.yofs, f))
6734 new_return(17);
6735
6736
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputzf(data.step, f))
6737 new_return(18);
6738
6739
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_putc(data.unblockable, f))
6740 new_return(19);
6741
6742
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputl(data.timeout, f))
6743 new_return(20);
6744
6745
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_putc(data.imitate_weapon, f))
6746 new_return(21);
6747
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_putc(data.default_defense, f))
6748 new_return(22);
6749
6750
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_putc(data.lift_level, f))
6751 new_return(23);
6752
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_putc(data.lift_time, f))
6753 new_return(24);
6754
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputzf(data.lift_height, f))
6755 new_return(25);
6756
6757
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputw(data.script, f))
6758 new_return(26);
6759
2/2
✓ Branch 0 taken 2181840 times.
✓ Branch 1 taken 272730 times.
2454570 for(uint q = 0; q < 8; ++q)
6760
1/2
✓ Branch 0 taken 2181840 times.
✗ Branch 1 not taken.
2181840 if(!p_iputl(data.initd[q], f))
6761 new_return(27);
6762
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputw(data.pierce_count, f))
6763 new_return(28);
6764 272730 return 0;
6765 }
6766
6767 130 bool write_midi(MIDI *m,PACKFILE *f)
6768 {
6769 int32_t c;
6770
6771
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 130 times.
130 if(!p_mputw(m->divisions,f)) return false;
6772
6773
2/2
✓ Branch 0 taken 4160 times.
✓ Branch 1 taken 130 times.
4290 for(c=0; c<MIDI_TRACKS; c++)
6774 {
6775
1/2
✓ Branch 0 taken 4160 times.
✗ Branch 1 not taken.
4160 if(!p_mputl(m->track[c].len,f)) return false;
6776
6777
2/2
✓ Branch 0 taken 2896 times.
✓ Branch 1 taken 1264 times.
4160 if(m->track[c].len > 0)
6778 {
6779
1/2
✓ Branch 0 taken 1264 times.
✗ Branch 1 not taken.
1264 if(!pfwrite(m->track[c].data,m->track[c].len,f))
6780 return false;
6781 1264 }
6782 4160 }
6783
6784 130 return true;
6785 130 }
6786
6787 9 int32_t writeheader(PACKFILE *f, zquestheader *Header)
6788 {
6789 9 dword section_id=ID_HEADER;
6790 9 dword section_version=V_HEADER;
6791 9 dword section_size=0;
6792
6793 //file header string
6794
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!pfwrite(Header->id_str,sizeof(Header->id_str),f))
6795 {
6796 new_return(1);
6797 }
6798
6799 //section id
6800
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
6801 {
6802 new_return(2);
6803 }
6804
6805 //section version info
6806
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
6807 {
6808 new_return(3);
6809 }
6810
6811
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
6812 {
6813 new_return(4);
6814 }
6815
6816
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 18 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
6817 {
6818 18 fake_pack_writing=(writecycle==0);
6819
6820 //section size
6821
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
6822 {
6823 new_return(5);
6824 }
6825
6826 18 writesize=0;
6827
6828 //finally... section data
6829
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(Header->zelda_version,f))
6830 {
6831 new_return(6);
6832 }
6833
6834
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(Header->build,f))
6835 {
6836 new_return(7);
6837 }
6838
6839
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(Header->pwd_hash,sizeof(Header->pwd_hash),f))
6840 {
6841 new_return(8);
6842 }
6843
6844
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(Header->internal,f))
6845 {
6846 new_return(10);
6847 }
6848
6849
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(Header->quest_number,f))
6850 {
6851 new_return(11);
6852 }
6853
6854
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(Header->version,16,f))
6855 {
6856 new_return(12);
6857 }
6858
6859
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(Header->minver,16,f))
6860 {
6861 new_return(13);
6862 }
6863
6864
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(Header->title,sizeof(Header->title),f))
6865 {
6866 new_return(14);
6867 }
6868
6869
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(Header->author,sizeof(Header->author),f))
6870 {
6871 new_return(15);
6872 }
6873
6874
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(Header->use_keyfile,f))
6875 {
6876 new_return(16);
6877 }
6878
6879
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(Header->data_flags,sizeof(Header->data_flags),f))
6880 {
6881 new_return(17);
6882 }
6883
6884
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(Header->templatepath,sizeof(Header->templatepath),f))
6885 {
6886 new_return(19);
6887 }
6888
6889
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(0,f)) //why are we doing this?
6890 //this is for map count, it seems. -Z
6891 {
6892 new_return(20);
6893 }
6894
6895 18 auto version = getVersion();
6896
6897
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(version.major,f))
6898 {
6899 new_return(21);
6900 }
6901
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(version.minor,f))
6902 {
6903 new_return(22);
6904 }
6905
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(version.patch,f))
6906 {
6907 new_return(23);
6908 }
6909 // Fourth component is deprecated.
6910
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(0,f))
6911 {
6912 new_return(24);
6913 }
6914
6915 // Numerous prerelease stages is deprecated.
6916
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(0,f))
6917 {
6918 new_return(25);
6919 }
6920
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(0,f))
6921 {
6922 new_return(26);
6923 }
6924
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(0,f))
6925 {
6926 new_return(27);
6927 }
6928
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(0,f))
6929 {
6930 new_return(28);
6931 }
6932
6933
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(BUILDTM_YEAR,f))
6934 {
6935 new_return(29);
6936 }
6937
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(BUILDTM_MONTH,f))
6938 {
6939 new_return(30);
6940 }
6941
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(BUILDTM_DAY,f))
6942 {
6943 new_return(31);
6944 }
6945
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(BUILDTM_HOUR,f))
6946 {
6947 new_return(32);
6948 }
6949
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(BUILDTM_MINUTE,f))
6950 {
6951 new_return(33);
6952 }
6953
6954 // This is no longer set to anything.
6955 const char* tempsig[256];
6956 18 memset(tempsig, 0, 256);
6957
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(&tempsig,256,f))
6958 {
6959 new_return(34);
6960 }
6961
6962 char tempcompilersig[256];
6963 18 memset(tempcompilersig, 0, 256);
6964 18 strcpy(tempcompilersig, COMPILER_NAME);
6965
6966
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(&tempcompilersig,256,f))
6967 {
6968 new_return(35);
6969 }
6970
6971 char tempcompilerversion[256];
6972 18 memset(tempcompilerversion, 0, 256);
6973 #ifdef _MSC_VER
6974 zc_itoa(_MSC_VER,tempcompilerversion,10);
6975 #else
6976 18 strcpy(tempcompilerversion, COMPILER_VERSION);
6977 #endif
6978
6979
6980
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(&tempcompilerversion,256,f))
6981 {
6982 new_return(36);
6983 }
6984
6985
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite("ZQuest Classic",1024,f))
6986 {
6987 new_return(37);
6988 }
6989
6990 // V_ZC_COMPILERSIG - a deprecated version field.
6991
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(1,f))
6992 {
6993 new_return(38);
6994 }
6995 #ifdef _MSC_VER
6996 if(!p_iputl((_MSC_VER / 100),f))
6997 {
6998 new_return(39);
6999 }
7000 #else
7001
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(COMPILER_V_FIRST,f))
7002 {
7003 new_return(39);
7004 }
7005 #endif
7006
7007
7008
7009 #ifdef _MSC_VER
7010 if(!p_iputl((_MSC_VER % 100),f))
7011 {
7012 new_return(41);
7013 }
7014 #else
7015
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(COMPILER_V_SECOND,f))
7016 {
7017 new_return(41);
7018 }
7019 #endif
7020
7021 #ifdef _MSC_VER
7022 # if _MSC_VER >= 1400
7023 if(!p_iputl((_MSC_FULL_VER % 100000),f))
7024 {
7025 new_return(40);
7026 }
7027 # else
7028 if(!p_iputl((_MSC_FULL_VER % 10000),f))
7029 {
7030 new_return(40);
7031 }
7032 #endif
7033 #else
7034
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(COMPILER_V_THIRD,f))
7035 {
7036 new_return(40);
7037 }
7038 #endif
7039
7040 #ifdef _MSC_VER
7041 if(!p_iputl((_MSC_BUILD),f))
7042 {
7043 new_return(42);
7044 }
7045 #else
7046
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(COMPILER_V_FOURTH,f))
7047 {
7048 new_return(42);
7049 }
7050 #endif
7051
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(0,f)) //was V_ZC_DEVSIG, no longer used
7052 {
7053 new_return(43);
7054 }
7055
7056 // Modules were removed (replaced by zinfo).
7057 char tempmodulename[1024];
7058 18 memset(tempmodulename, 0, 1024);
7059
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(&tempmodulename,1024,f))
7060 {
7061 new_return(44);
7062 }
7063
7064 char tempdate[256];
7065 18 memset(tempdate, 0, 256);
7066 18 strcpy(tempdate, __DATE__);
7067
7068
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(&tempdate,256,f))
7069 {
7070 new_return(45);
7071 }
7072 char temptime[256];
7073 18 memset(temptime, 0, 256);
7074 18 strcpy(temptime, __TIME__);
7075
7076
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(&temptime,256,f))
7077 {
7078 new_return(46);
7079 }
7080
7081
7082 char temptimezone[6];
7083 18 memset(temptimezone, 0, 6);
7084 18 strcpy(temptimezone, __TIMEZONE__);
7085
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(&temptimezone,6,f))
7086 {
7087 new_return(47);
7088 }
7089
7090
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(Header->external_zinfo ? 1 : 0, f))
7091 {
7092 new_return(48);
7093 }
7094
7095
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(isStableRelease() ? 0 : 1, f))
7096 {
7097 new_return(49);
7098 }
7099
7100
3/6
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 18 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 18 times.
✗ Branch 5 not taken.
18 if(!p_putcstr(version.version_string, f))
7101 {
7102 new_return(50);
7103 }
7104
7105
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
7106 {
7107 9 section_size=writesize;
7108 9 }
7109 18 }
7110
7111
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
7112 {
7113 char ebuf[80];
7114 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
7115 jwin_alert("Error: writeheader()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
7116 }
7117
7118 9 new_return(0);
7119 }
7120
7121 9 int32_t writerules(PACKFILE *f, zquestheader *Header)
7122 {
7123 //these are here to bypass compiler warnings about unused arguments
7124 9 Header=Header;
7125
7126 9 dword section_id=ID_RULES;
7127 9 dword section_version=V_RULES;
7128 9 dword section_size=0;
7129
7130 //section id
7131
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
7132 {
7133 new_return(1);
7134 }
7135
7136 //section version info
7137
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
7138 {
7139 new_return(2);
7140 }
7141
7142
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!write_deprecated_section_cversion(section_version,f))
7143 {
7144 new_return(3);
7145 }
7146
7147
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!p_iputl(V_COMPATRULE,f))
7148 {
7149 new_return(6);
7150 }
7151
7152
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 18 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
7153 {
7154 18 fake_pack_writing=(writecycle==0);
7155
7156 //section size
7157
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
7158 {
7159 new_return(4);
7160 }
7161
7162 18 writesize=0;
7163
7164 //finally... section data
7165
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(quest_rules,QUESTRULES_NEW_SIZE,f))
7166 {
7167 new_return(5);
7168 }
7169
7170
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
7171 {
7172 9 section_size=writesize;
7173 9 }
7174 18 }
7175
7176
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
7177 {
7178 char ebuf[80];
7179 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
7180 jwin_alert("Error: writerules()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
7181 }
7182
7183 9 new_return(0);
7184 }
7185
7186
7187 9 int32_t writedoorcombosets(PACKFILE *f, zquestheader *Header)
7188 {
7189 //these are here to bypass compiler warnings about unused arguments
7190 9 Header=Header;
7191
7192 9 dword section_id=ID_DOORS;
7193 9 dword section_version=V_DOORS;
7194 9 dword section_size=0;
7195
7196 //section id
7197
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
7198 {
7199 new_return(1);
7200 }
7201
7202 //section version info
7203
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
7204 {
7205 new_return(2);
7206 }
7207
7208
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
7209 {
7210 new_return(3);
7211 }
7212
7213
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
7214 {
7215 18 fake_pack_writing=(writecycle==0);
7216
7217 //section size
7218
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
7219 {
7220 new_return(4);
7221 }
7222
7223 18 writesize=0;
7224
7225 //finally... section data
7226
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(door_combo_set_count,f))
7227 {
7228 new_return(5);
7229 }
7230
7231
2/2
✓ Branch 0 taken 320 times.
✓ Branch 1 taken 18 times.
338 for(int32_t i=0; i<door_combo_set_count; i++)
7232 {
7233 //name
7234 char name[21];
7235 320 memset(name, 21, (char)0);
7236 320 strcpy(name, DoorComboSetNames[i].c_str());
7237
1/2
✓ Branch 0 taken 320 times.
✗ Branch 1 not taken.
320 if(!pfwrite(name,sizeof(name),f))
7238 {
7239 new_return(6);
7240 }
7241
7242 //up door
7243
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 320 times.
3200 for(int32_t j=0; j<9; j++)
7244 {
7245
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 11520 times.
14400 for(int32_t k=0; k<4; k++)
7246 {
7247
1/2
✓ Branch 0 taken 11520 times.
✗ Branch 1 not taken.
11520 if(!p_iputw(DoorComboSets[i].doorcombo_u[j][k],f))
7248 {
7249 new_return(7);
7250 }
7251 11520 }
7252 2880 }
7253
7254
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 320 times.
3200 for(int32_t j=0; j<9; j++)
7255 {
7256
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 11520 times.
14400 for(int32_t k=0; k<4; k++)
7257 {
7258
1/2
✓ Branch 0 taken 11520 times.
✗ Branch 1 not taken.
11520 if(!p_putc(DoorComboSets[i].doorcset_u[j][k],f))
7259 {
7260 new_return(8);
7261 }
7262 11520 }
7263 2880 }
7264
7265 //down door
7266
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 320 times.
3200 for(int32_t j=0; j<9; j++)
7267 {
7268
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 11520 times.
14400 for(int32_t k=0; k<4; k++)
7269 {
7270
1/2
✓ Branch 0 taken 11520 times.
✗ Branch 1 not taken.
11520 if(!p_iputw(DoorComboSets[i].doorcombo_d[j][k],f))
7271 {
7272 new_return(9);
7273 }
7274 11520 }
7275 2880 }
7276
7277
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 320 times.
3200 for(int32_t j=0; j<9; j++)
7278 {
7279
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 11520 times.
14400 for(int32_t k=0; k<4; k++)
7280 {
7281
1/2
✓ Branch 0 taken 11520 times.
✗ Branch 1 not taken.
11520 if(!p_putc(DoorComboSets[i].doorcset_d[j][k],f))
7282 {
7283 new_return(10);
7284 }
7285 11520 }
7286 2880 }
7287
7288
7289 //left door
7290
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 320 times.
3200 for(int32_t j=0; j<9; j++)
7291 {
7292
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 17280 times.
20160 for(int32_t k=0; k<6; k++)
7293 {
7294
1/2
✓ Branch 0 taken 17280 times.
✗ Branch 1 not taken.
17280 if(!p_iputw(DoorComboSets[i].doorcombo_l[j][k],f))
7295
7296 {
7297 new_return(11);
7298 }
7299 17280 }
7300 2880 }
7301
7302
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 320 times.
3200 for(int32_t j=0; j<9; j++)
7303 {
7304
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 17280 times.
20160 for(int32_t k=0; k<6; k++)
7305 {
7306
1/2
✓ Branch 0 taken 17280 times.
✗ Branch 1 not taken.
17280 if(!p_putc(DoorComboSets[i].doorcset_l[j][k],f))
7307 {
7308 new_return(12);
7309 }
7310 17280 }
7311 2880 }
7312
7313 //right door
7314
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 320 times.
3200 for(int32_t j=0; j<9; j++)
7315 {
7316
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 17280 times.
20160 for(int32_t k=0; k<6; k++)
7317 {
7318
1/2
✓ Branch 0 taken 17280 times.
✗ Branch 1 not taken.
17280 if(!p_iputw(DoorComboSets[i].doorcombo_r[j][k],f))
7319 {
7320 new_return(13);
7321 }
7322 17280 }
7323 2880 }
7324
7325
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 320 times.
3200 for(int32_t j=0; j<9; j++)
7326 {
7327
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 17280 times.
20160 for(int32_t k=0; k<6; k++)
7328 {
7329
1/2
✓ Branch 0 taken 17280 times.
✗ Branch 1 not taken.
17280 if(!p_putc(DoorComboSets[i].doorcset_r[j][k],f))
7330 {
7331 new_return(14);
7332 }
7333 17280 }
7334 2880 }
7335
7336
7337 //up bomb rubble
7338
2/2
✓ Branch 0 taken 640 times.
✓ Branch 1 taken 320 times.
960 for(int32_t j=0; j<2; j++)
7339 {
7340
1/2
✓ Branch 0 taken 640 times.
✗ Branch 1 not taken.
640 if(!p_iputw(DoorComboSets[i].bombdoorcombo_u[j],f))
7341 {
7342 new_return(15);
7343 }
7344 640 }
7345
7346
2/2
✓ Branch 0 taken 640 times.
✓ Branch 1 taken 320 times.
960 for(int32_t j=0; j<2; j++)
7347 {
7348
1/2
✓ Branch 0 taken 640 times.
✗ Branch 1 not taken.
640 if(!p_putc(DoorComboSets[i].bombdoorcset_u[j],f))
7349 {
7350 new_return(16);
7351 }
7352 640 }
7353
7354 //down bomb rubble
7355
2/2
✓ Branch 0 taken 640 times.
✓ Branch 1 taken 320 times.
960 for(int32_t j=0; j<2; j++)
7356 {
7357
1/2
✓ Branch 0 taken 640 times.
✗ Branch 1 not taken.
640 if(!p_iputw(DoorComboSets[i].bombdoorcombo_d[j],f))
7358 {
7359 new_return(17);
7360 }
7361 640 }
7362
7363
2/2
✓ Branch 0 taken 640 times.
✓ Branch 1 taken 320 times.
960 for(int32_t j=0; j<2; j++)
7364 {
7365
1/2
✓ Branch 0 taken 640 times.
✗ Branch 1 not taken.
640 if(!p_putc(DoorComboSets[i].bombdoorcset_d[j],f))
7366 {
7367 new_return(18);
7368 }
7369 640 }
7370
7371 //left bomb rubble
7372
2/2
✓ Branch 0 taken 960 times.
✓ Branch 1 taken 320 times.
1280 for(int32_t j=0; j<3; j++)
7373 {
7374
1/2
✓ Branch 0 taken 960 times.
✗ Branch 1 not taken.
960 if(!p_iputw(DoorComboSets[i].bombdoorcombo_l[j],f))
7375 {
7376 new_return(19);
7377 }
7378 960 }
7379
7380
2/2
✓ Branch 0 taken 960 times.
✓ Branch 1 taken 320 times.
1280 for(int32_t j=0; j<3; j++)
7381 {
7382
1/2
✓ Branch 0 taken 960 times.
✗ Branch 1 not taken.
960 if(!p_putc(DoorComboSets[i].bombdoorcset_l[j],f))
7383 {
7384 new_return(20);
7385 }
7386 960 }
7387
7388 //right bomb rubble
7389
2/2
✓ Branch 0 taken 960 times.
✓ Branch 1 taken 320 times.
1280 for(int32_t j=0; j<3; j++)
7390 {
7391
1/2
✓ Branch 0 taken 960 times.
✗ Branch 1 not taken.
960 if(!p_iputw(DoorComboSets[i].bombdoorcombo_r[j],f))
7392 {
7393 new_return(21);
7394 }
7395 960 }
7396
7397
2/2
✓ Branch 0 taken 960 times.
✓ Branch 1 taken 320 times.
1280 for(int32_t j=0; j<3; j++)
7398 {
7399
1/2
✓ Branch 0 taken 960 times.
✗ Branch 1 not taken.
960 if(!p_putc(DoorComboSets[i].bombdoorcset_r[j],f))
7400 {
7401 new_return(22);
7402 }
7403 960 }
7404
7405 //walkthrough stuff
7406
2/2
✓ Branch 0 taken 1280 times.
✓ Branch 1 taken 320 times.
1600 for(int32_t j=0; j<4; j++)
7407 {
7408
1/2
✓ Branch 0 taken 1280 times.
✗ Branch 1 not taken.
1280 if(!p_iputw(DoorComboSets[i].walkthroughcombo[j],f))
7409 {
7410 new_return(23);
7411 }
7412 1280 }
7413
7414
2/2
✓ Branch 0 taken 1280 times.
✓ Branch 1 taken 320 times.
1600 for(int32_t j=0; j<4; j++)
7415 {
7416
1/2
✓ Branch 0 taken 1280 times.
✗ Branch 1 not taken.
1280 if(!p_putc(DoorComboSets[i].walkthroughcset[j],f))
7417 {
7418 new_return(24);
7419 }
7420 1280 }
7421
7422 //flags
7423
2/2
✓ Branch 0 taken 640 times.
✓ Branch 1 taken 320 times.
960 for(int32_t j=0; j<2; j++)
7424 {
7425
1/2
✓ Branch 0 taken 640 times.
✗ Branch 1 not taken.
640 if(!p_putc(DoorComboSets[i].flags[j],f))
7426 {
7427 new_return(25);
7428 }
7429 640 }
7430 320 }
7431
7432
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
7433 {
7434 9 section_size=writesize;
7435 9 }
7436 18 }
7437
7438
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
7439 {
7440 char ebuf[80];
7441 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
7442 jwin_alert("Error: writedoorcombosets()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
7443 }
7444
7445 9 new_return(0);
7446 }
7447
7448 9216 int32_t write_one_dmap(PACKFILE* f, int index)
7449 {
7450 9216 DMaps[index].validate_subscreens();
7451
7452
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[index].map,f))
7453 {
7454 new_return(6);
7455 }
7456
7457
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(DMaps[index].level,f))
7458 {
7459 new_return(7);
7460 }
7461
7462
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[index].xoff,f))
7463 {
7464 new_return(8);
7465 }
7466
7467
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[index].compass,f))
7468 {
7469 new_return(9);
7470 }
7471
7472
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(DMaps[index].color,f))
7473 {
7474 new_return(10);
7475 }
7476
7477
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[index].midi,f))
7478 {
7479 new_return(11);
7480 }
7481
7482
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[index].cont,f))
7483 {
7484 new_return(12);
7485 }
7486
7487
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[index].type,f))
7488 {
7489 new_return(13);
7490 }
7491
7492
2/2
✓ Branch 0 taken 73728 times.
✓ Branch 1 taken 9216 times.
82944 for(int32_t j=0; j<8; j++)
7493 {
7494
1/2
✓ Branch 0 taken 73728 times.
✗ Branch 1 not taken.
73728 if(!p_putc(DMaps[index].grid[j],f))
7495 {
7496 new_return(14);
7497 }
7498 73728 }
7499
7500
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!pfwrite(&DMaps[index].name,sizeof(DMaps[0].name)-1,f))
7501 {
7502 new_return(15);
7503 }
7504
7505
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putwstr(DMaps[index].title,f))
7506 {
7507 new_return(16);
7508 }
7509
7510
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!pfwrite(&DMaps[index].intro,sizeof(DMaps[0].intro)-1,f))
7511 {
7512 new_return(17);
7513 }
7514
7515
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(DMaps[index].minimap_tile[0],f))
7516 {
7517 new_return(18);
7518 }
7519
7520
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[index].minimap_cset[0],f))
7521 {
7522 new_return(19);
7523 }
7524
7525
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(DMaps[index].minimap_tile[1],f))
7526 {
7527 new_return(20);
7528 }
7529
7530
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[index].minimap_cset[1],f))
7531 {
7532 new_return(21);
7533 }
7534
7535
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(DMaps[index].largemap_tile[0],f))
7536 {
7537 new_return(22);
7538 }
7539
7540
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[index].largemap_cset[0],f))
7541 {
7542 new_return(23);
7543 }
7544
7545
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(DMaps[index].largemap_tile[1],f))
7546 {
7547 new_return(24);
7548 }
7549
7550
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[index].largemap_cset[1],f))
7551 {
7552 new_return(25);
7553 }
7554
7555
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!pfwrite(&DMaps[index].tmusic,sizeof(DMaps[0].tmusic)-1,f))
7556 {
7557 new_return(26);
7558 }
7559
7560
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[index].tmusictrack,f))
7561 {
7562 new_return(25);
7563 }
7564
7565
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[index].active_subscreen,f))
7566 {
7567 new_return(26);
7568 }
7569
7570
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[index].passive_subscreen,f))
7571 {
7572 new_return(27);
7573 }
7574
7575 byte disabled[32];
7576 9216 memset(disabled,0,32);
7577
7578
2/2
✓ Branch 0 taken 2359296 times.
✓ Branch 1 taken 9216 times.
2368512 for(int32_t j=0; j<MAXITEMS; j++)
7579 {
7580
1/2
✓ Branch 0 taken 2359296 times.
✗ Branch 1 not taken.
2359296 if(DMaps[index].disableditems[j])
7581 {
7582 disabled[j/8] |= (1 << (j%8));
7583 }
7584 2359296 }
7585
7586
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!pfwrite(disabled,32,f))
7587 {
7588 new_return(28);
7589 }
7590
7591
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(DMaps[index].flags,f))
7592 new_return(29);
7593
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[index].sideview,f))
7594 new_return(30);
7595
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(DMaps[index].script,f))
7596 new_return(31);
7597
2/2
✓ Branch 0 taken 73728 times.
✓ Branch 1 taken 9216 times.
82944 for ( int32_t q = 0; q < 8; q++ )
7598
1/2
✓ Branch 0 taken 73728 times.
✗ Branch 1 not taken.
73728 if(!p_iputl(DMaps[index].initD[q],f))
7599 new_return(32);
7600
2/2
✓ Branch 0 taken 73728 times.
✓ Branch 1 taken 9216 times.
82944 for ( int32_t q = 0; q < 8; q++ )
7601
2/2
✓ Branch 0 taken 4792320 times.
✓ Branch 1 taken 73728 times.
4866048 for ( int32_t w = 0; w < 65; w++ )
7602
1/2
✓ Branch 0 taken 4792320 times.
✗ Branch 1 not taken.
4792320 if (!p_putc(DMaps[index].initD_label[q][w],f))
7603 73728 new_return(33);
7604
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(DMaps[index].active_sub_script,f))
7605 new_return(34);
7606
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(DMaps[index].passive_sub_script,f))
7607 new_return(35);
7608
2/2
✓ Branch 0 taken 73728 times.
✓ Branch 1 taken 9216 times.
82944 for(int32_t q = 0; q < 8; ++q)
7609
1/2
✓ Branch 0 taken 73728 times.
✗ Branch 1 not taken.
73728 if(!p_iputl(DMaps[index].sub_initD[q],f))
7610 new_return(36);
7611
2/2
✓ Branch 0 taken 73728 times.
✓ Branch 1 taken 9216 times.
82944 for(int32_t q = 0; q < 8; ++q)
7612
2/2
✓ Branch 0 taken 4792320 times.
✓ Branch 1 taken 73728 times.
4866048 for(int32_t w = 0; w < 65; ++w)
7613
1/2
✓ Branch 0 taken 4792320 times.
✗ Branch 1 not taken.
4792320 if(!p_putc(DMaps[index].sub_initD_label[q][w],f))
7614 73728 new_return(37);
7615
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(DMaps[index].onmap_script,f))
7616 new_return(38);
7617
2/2
✓ Branch 0 taken 73728 times.
✓ Branch 1 taken 9216 times.
82944 for(int32_t q = 0; q < 8; ++q)
7618
1/2
✓ Branch 0 taken 73728 times.
✗ Branch 1 not taken.
73728 if(!p_iputl(DMaps[index].onmap_initD[q],f))
7619 new_return(39);
7620
2/2
✓ Branch 0 taken 73728 times.
✓ Branch 1 taken 9216 times.
82944 for(int32_t q = 0; q < 8; ++q)
7621
2/2
✓ Branch 0 taken 4792320 times.
✓ Branch 1 taken 73728 times.
4866048 for(int32_t w = 0; w < 65; ++w)
7622
1/2
✓ Branch 0 taken 4792320 times.
✗ Branch 1 not taken.
4792320 if(!p_putc(DMaps[index].onmap_initD_label[q][w],f))
7623 73728 new_return(40);
7624
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(DMaps[index].mirrorDMap,f))
7625 new_return(41);
7626
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if (!p_iputl(DMaps[index].tmusic_loop_start, f))
7627 new_return(42);
7628
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if (!p_iputl(DMaps[index].tmusic_loop_end, f))
7629 new_return(43);
7630
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if (!p_iputl(DMaps[index].tmusic_xfade_in, f))
7631 new_return(44);
7632
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if (!p_iputl(DMaps[index].tmusic_xfade_out, f))
7633 new_return(45);
7634
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[index].overlay_subscreen, f))
7635 new_return(46);
7636
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if (!p_iputl(DMaps[index].intro_string_id, f))
7637 new_return(47);
7638
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if (DMaps[index].flags & dmfCUSTOM_GRAVITY)
7639 {
7640 if (!p_iputzf(DMaps[index].dmap_gravity, f))
7641 new_return(48);
7642 if (!p_iputzf(DMaps[index].dmap_terminal_v, f))
7643 new_return(49);
7644 }
7645
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(DMaps[index].map_subscreen, f))
7646 new_return(50);
7647
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[index].floor, f))
7648 new_return(51);
7649 9216 return 0;
7650 }
7651 9 int32_t writedmaps(PACKFILE *f, word, word, word start_dmap, word max_dmaps)
7652 {
7653 9 word dmap_count=count_dmaps();
7654 9 dword section_id=ID_DMAPS;
7655 9 dword section_version=V_DMAPS;
7656 9 dword section_size=0;
7657
7658 //section id
7659
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
7660 {
7661 new_return(1);
7662 }
7663
7664 //section version info
7665
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
7666 {
7667 new_return(2);
7668 }
7669
7670
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
7671 {
7672 new_return(3);
7673 }
7674
7675
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
7676 {
7677 18 fake_pack_writing=(writecycle==0);
7678
7679 //section size
7680
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
7681 {
7682 new_return(4);
7683 }
7684
7685 18 writesize=0;
7686
7687
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 dmap_count=zc_min(dmap_count, max_dmaps);
7688
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 dmap_count=zc_min(dmap_count, MAXDMAPS-start_dmap);
7689
7690 //finally... section data
7691
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(dmap_count,f))
7692 {
7693 new_return(5);
7694 }
7695
7696
7697
2/2
✓ Branch 0 taken 9216 times.
✓ Branch 1 taken 18 times.
9234 for(int32_t i=start_dmap; i<start_dmap+dmap_count; i++)
7698 {
7699
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9216 times.
9216 if (auto ret = write_one_dmap(f, i))
7700 return ret;
7701 9216 }
7702
7703
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
7704 {
7705 9 section_size=writesize;
7706 9 }
7707 18 }
7708
7709
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
7710 {
7711 char ebuf[80];
7712 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
7713 jwin_alert("Error: writedmaps()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
7714 }
7715
7716 9 new_return(0);
7717 9 }
7718
7719 9 int32_t writemisccolors(PACKFILE *f, zquestheader *Header)
7720 {
7721 //these are here to bypass compiler warnings about unused arguments
7722 9 Header=Header;
7723
7724 9 dword section_id=ID_COLORS;
7725 9 dword section_version=V_COLORS;
7726 9 dword section_size = 0;
7727
7728 //section id
7729
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
7730 {
7731 new_return(1);
7732 }
7733
7734
7735 //section version info
7736
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
7737 {
7738 new_return(2);
7739 }
7740
7741
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
7742 {
7743 new_return(3);
7744 }
7745
7746
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 18 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
7747 {
7748 18 fake_pack_writing=(writecycle==0);
7749
7750 //section size
7751
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
7752 {
7753 new_return(4);
7754 }
7755
7756 18 writesize=0;
7757
7758
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.text,f))
7759 {
7760 new_return(5);
7761 }
7762
7763
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.caption,f))
7764 {
7765 new_return(6);
7766 }
7767
7768
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.overw_bg,f))
7769 {
7770 new_return(7);
7771 }
7772
7773
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.dngn_bg,f))
7774 {
7775 new_return(8);
7776 }
7777
7778
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.dngn_fg,f))
7779 {
7780 new_return(9);
7781 }
7782
7783
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.cave_fg,f))
7784 {
7785 new_return(10);
7786 }
7787
7788
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.bs_dk,f))
7789 {
7790 new_return(11);
7791 }
7792
7793
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.bs_goal,f))
7794 {
7795 new_return(12);
7796 }
7797
7798
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.compass_lt,f))
7799 {
7800 new_return(13);
7801 }
7802
7803
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.compass_dk,f))
7804 {
7805 new_return(14);
7806 }
7807
7808
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.subscr_bg,f))
7809 {
7810 new_return(15);
7811 }
7812
7813
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.triframe_color,f))
7814 {
7815 new_return(16);
7816 }
7817
7818
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.hero_dot,f))
7819 {
7820 new_return(17);
7821 }
7822
7823
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.bmap_bg,f))
7824 {
7825 new_return(18);
7826 }
7827
7828
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.bmap_fg,f))
7829 {
7830 new_return(19);
7831 }
7832
7833
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.triforce_cset,f))
7834 {
7835 new_return(20);
7836 }
7837
7838
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.triframe_cset,f))
7839 {
7840 new_return(21);
7841 }
7842
7843
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.overworld_map_cset,f))
7844 {
7845 new_return(22);
7846 }
7847
7848
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.dungeon_map_cset,f))
7849 {
7850 new_return(23);
7851 }
7852
7853
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.blueframe_cset,f))
7854 {
7855 new_return(24);
7856 }
7857
7858
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.HCpieces_cset,f))
7859 {
7860 new_return(31);
7861 }
7862
7863
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.subscr_shadow,f))
7864 {
7865 new_return(32);
7866 }
7867
7868
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.msgtext,f))
7869 {
7870 new_return(33);
7871 }
7872
7873
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(QMisc.colors.triforce_tile,f))
7874 {
7875 new_return(34);
7876 }
7877
7878
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(QMisc.colors.triframe_tile,f))
7879 {
7880 new_return(35);
7881 }
7882
7883
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(QMisc.colors.overworld_map_tile,f))
7884 {
7885 new_return(36);
7886 }
7887
7888
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(QMisc.colors.dungeon_map_tile,f))
7889 {
7890 new_return(37);
7891 }
7892
7893
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(QMisc.colors.blueframe_tile,f))
7894 {
7895 new_return(38);
7896 }
7897
7898
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(QMisc.colors.HCpieces_tile,f))
7899 {
7900 new_return(39);
7901 }
7902
7903
7904
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
7905 {
7906 9 section_size=writesize;
7907 9 }
7908 18 }
7909
7910
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
7911 {
7912 char ebuf[80];
7913 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
7914 jwin_alert("Error: writemisccolors()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
7915 }
7916
7917 9 new_return(0);
7918 }
7919
7920 9 int32_t writegameicons(PACKFILE *f, zquestheader *Header)
7921 {
7922 //these are here to bypass compiler warnings about unused arguments
7923 9 Header=Header;
7924
7925 9 dword section_id=ID_ICONS;
7926 9 dword section_version=V_ICONS;
7927 9 dword section_size = 0;
7928
7929 //section id
7930
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
7931 {
7932 new_return(1);
7933 }
7934
7935 //section version info
7936
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
7937 {
7938 new_return(2);
7939 }
7940
7941
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
7942 {
7943 new_return(3);
7944 }
7945
7946
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 18 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
7947 {
7948 18 fake_pack_writing=(writecycle==0);
7949
7950 //section size
7951
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
7952 {
7953 new_return(4);
7954 }
7955
7956 18 writesize=0;
7957
7958
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t i=0; i<4; i++)
7959 {
7960
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(QMisc.icons[i],f))
7961 {
7962 new_return(5);
7963 }
7964 72 }
7965
7966
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
7967 {
7968 9 section_size=writesize;
7969 9 }
7970 18 }
7971
7972
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
7973 {
7974 char ebuf[80];
7975 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
7976 jwin_alert("Error: writegameicons()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
7977 }
7978
7979 9 new_return(0);
7980 }
7981
7982 9 int32_t writemisc(PACKFILE *f, zquestheader *Header)
7983 {
7984 //these are here to bypass compiler warnings about unused arguments
7985 9 Header=Header;
7986
7987 9 dword section_id=ID_MISC;
7988 9 dword section_version=V_MISC;
7989 9 word shops=count_shops(&QMisc);
7990 9 word infos=count_infos(&QMisc);
7991 9 word warprings=count_warprings(&QMisc);
7992 9 word triforces=8;
7993 9 dword section_size = 0;
7994
7995 //section id
7996
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
7997 {
7998 new_return(1);
7999 }
8000
8001
8002 //section version info
8003
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
8004 {
8005 new_return(2);
8006 }
8007
8008
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
8009 {
8010 new_return(3);
8011 }
8012
8013
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
8014 {
8015 18 fake_pack_writing=(writecycle==0);
8016
8017 //section size
8018
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
8019 {
8020 new_return(4);
8021 }
8022
8023 18 writesize=0;
8024
8025 //shops
8026
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(shops,f))
8027 {
8028 new_return(5);
8029 }
8030
8031
2/2
✓ Branch 0 taken 160 times.
✓ Branch 1 taken 18 times.
178 for(int32_t i=0; i<shops; i++)
8032 {
8033
1/2
✓ Branch 0 taken 160 times.
✗ Branch 1 not taken.
160 if(!pfwrite(QMisc.shop[i].name,sizeof(QMisc.shop[i].name)-1,f))
8034 {
8035 new_return(6);
8036 }
8037
8038
2/2
✓ Branch 0 taken 480 times.
✓ Branch 1 taken 160 times.
640 for(int32_t j=0; j<3; j++)
8039 {
8040
1/2
✓ Branch 0 taken 480 times.
✗ Branch 1 not taken.
480 if(!p_putc(QMisc.shop[i].item[j],f))
8041 {
8042 new_return(7);
8043 }
8044 480 }
8045
8046
2/2
✓ Branch 0 taken 480 times.
✓ Branch 1 taken 160 times.
640 for(int32_t j=0; j<3; j++)
8047 {
8048
1/2
✓ Branch 0 taken 480 times.
✗ Branch 1 not taken.
480 if(!p_iputw(QMisc.shop[i].price[j],f))
8049 {
8050 new_return(8);
8051 }
8052 480 }
8053
8054
2/2
✓ Branch 0 taken 480 times.
✓ Branch 1 taken 160 times.
640 for(int32_t j=0; j<3; j++)
8055 {
8056
1/2
✓ Branch 0 taken 480 times.
✗ Branch 1 not taken.
480 if(!p_putc(QMisc.shop[i].hasitem[j],f))
8057 {
8058 new_return(9);
8059 }
8060 480 }
8061 160 }
8062
8063 //infos
8064
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(infos,f))
8065 {
8066 new_return(10);
8067 }
8068
8069
2/2
✓ Branch 0 taken 160 times.
✓ Branch 1 taken 18 times.
178 for(int32_t i=0; i<infos; i++)
8070 {
8071
1/2
✓ Branch 0 taken 160 times.
✗ Branch 1 not taken.
160 if(!pfwrite(QMisc.info[i].name,sizeof(QMisc.info[i].name)-1,f))
8072 {
8073 new_return(11);
8074 }
8075
8076
2/2
✓ Branch 0 taken 480 times.
✓ Branch 1 taken 160 times.
640 for(int32_t j=0; j<3; j++)
8077 {
8078
1/2
✓ Branch 0 taken 480 times.
✗ Branch 1 not taken.
480 if(!p_iputw(QMisc.info[i].str[j],f))
8079 {
8080 new_return(12);
8081 }
8082 480 }
8083
8084
2/2
✓ Branch 0 taken 480 times.
✓ Branch 1 taken 160 times.
640 for(int32_t j=0; j<3; j++)
8085 {
8086
1/2
✓ Branch 0 taken 480 times.
✗ Branch 1 not taken.
480 if(!p_iputw(QMisc.info[i].price[j],f))
8087 {
8088 new_return(13);
8089 }
8090 480 }
8091 160 }
8092
8093 //warp rings
8094
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(warprings,f))
8095 {
8096 new_return(14);
8097 }
8098
8099
2/2
✓ Branch 0 taken 208 times.
✓ Branch 1 taken 18 times.
226 for(int32_t i=0; i<warprings; i++)
8100 {
8101
2/2
✓ Branch 0 taken 1872 times.
✓ Branch 1 taken 208 times.
2080 for(int32_t j=0; j<9; j++)
8102 {
8103
1/2
✓ Branch 0 taken 1872 times.
✗ Branch 1 not taken.
1872 if(!p_iputw(QMisc.warp[i].dmap[j],f))
8104 {
8105 new_return(15);
8106 }
8107 1872 }
8108
8109
2/2
✓ Branch 0 taken 1872 times.
✓ Branch 1 taken 208 times.
2080 for(int32_t j=0; j<9; j++)
8110 {
8111
1/2
✓ Branch 0 taken 1872 times.
✗ Branch 1 not taken.
1872 if(!p_putc(QMisc.warp[i].scr[j],f))
8112 {
8113 new_return(16);
8114 }
8115 1872 }
8116
8117
1/2
✓ Branch 0 taken 208 times.
✗ Branch 1 not taken.
208 if(!p_putc(QMisc.warp[i].size,f))
8118 {
8119 new_return(17);
8120 }
8121 208 }
8122
8123 //triforce pieces
8124
2/2
✓ Branch 0 taken 144 times.
✓ Branch 1 taken 18 times.
162 for(int32_t i=0; i<triforces; i++)
8125 {
8126
1/2
✓ Branch 0 taken 144 times.
✗ Branch 1 not taken.
144 if(!p_putc(QMisc.triforce[i],f))
8127 {
8128 new_return(18);
8129 }
8130 144 }
8131
8132 //end string
8133
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(QMisc.endstring,f))
8134 {
8135 new_return(19);
8136 }
8137
8138 //V_MISC >= 8
8139
2/2
✓ Branch 0 taken 160 times.
✓ Branch 1 taken 18 times.
178 for(int32_t i=0; i<shops; i++)
8140 {
8141
2/2
✓ Branch 0 taken 160 times.
✓ Branch 1 taken 480 times.
640 for(int32_t j=0; j<3; j++)
8142 {
8143
1/2
✓ Branch 0 taken 480 times.
✗ Branch 1 not taken.
480 if(!p_iputw(QMisc.shop[i].str[j],f))
8144 {
8145 new_return(20);
8146 }
8147 480 }
8148 160 }
8149 //V_MISC >= 9
8150
2/2
✓ Branch 0 taken 576 times.
✓ Branch 1 taken 18 times.
594 for ( int32_t q = 0; q < 32; q++ )
8151 {
8152
1/2
✓ Branch 0 taken 576 times.
✗ Branch 1 not taken.
576 if(!p_iputl(QMisc.questmisc[q],f))
8153 new_return(21);
8154 576 }
8155
2/2
✓ Branch 0 taken 576 times.
✓ Branch 1 taken 18 times.
594 for ( int32_t q = 0; q < 32; q++ )
8156 {
8157
2/2
✓ Branch 0 taken 73728 times.
✓ Branch 1 taken 576 times.
74304 for ( int32_t j = 0; j < 128; j++ )
8158
1/2
✓ Branch 0 taken 73728 times.
✗ Branch 1 not taken.
73728 if(!p_putc(0,f))
8159 new_return(22);
8160 576 }
8161 //V_MISC >= 11
8162
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(QMisc.zscript_last_compiled_version,f))
8163 new_return(23);
8164
8165 //V_MISC >= 12
8166
2/2
✓ Branch 0 taken 4608 times.
✓ Branch 1 taken 18 times.
4626 for(int32_t q = 0; q < sprMAX; ++q)
8167 {
8168
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(QMisc.sprites[q],f))
8169 new_return(24);
8170 4608 }
8171
8172 //V_MISC >= 13
8173
2/2
✓ Branch 0 taken 1152 times.
✓ Branch 1 taken 18 times.
1170 for(size_t q = 0; q < 64; ++q)
8174 {
8175 1152 bottletype* bt = &(QMisc.bottle_types[q]);
8176
1/2
✓ Branch 0 taken 1152 times.
✗ Branch 1 not taken.
1152 if (!pfwrite(bt->name, 32, f))
8177 new_return(25);
8178
2/2
✓ Branch 0 taken 3456 times.
✓ Branch 1 taken 1152 times.
4608 for(size_t j = 0; j < 3; ++j)
8179 {
8180
1/2
✓ Branch 0 taken 3456 times.
✗ Branch 1 not taken.
3456 if (!p_putc(bt->counter[j], f))
8181 new_return(25);
8182
1/2
✓ Branch 0 taken 3456 times.
✗ Branch 1 not taken.
3456 if (!p_iputw(bt->amount[j], f))
8183 new_return(25);
8184 3456 }
8185
1/2
✓ Branch 0 taken 1152 times.
✗ Branch 1 not taken.
1152 if (!p_putc(bt->flags, f))
8186 new_return(25);
8187
1/2
✓ Branch 0 taken 1152 times.
✗ Branch 1 not taken.
1152 if (!p_putc(bt->next_type, f))
8188 new_return(25);
8189 1152 }
8190
2/2
✓ Branch 0 taken 4608 times.
✓ Branch 1 taken 18 times.
4626 for(size_t q = 0; q < 256; ++q)
8191 {
8192 4608 bottleshoptype* bst = &(QMisc.bottle_shop_types[q]);
8193
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if (!pfwrite(bst->name, 32, f))
8194 new_return(26);
8195
2/2
✓ Branch 0 taken 13824 times.
✓ Branch 1 taken 4608 times.
18432 for(size_t j = 0; j < 3; ++j)
8196 {
8197
1/2
✓ Branch 0 taken 13824 times.
✗ Branch 1 not taken.
13824 if (!p_putc(bst->fill[j], f))
8198 new_return(26);
8199
1/2
✓ Branch 0 taken 13824 times.
✗ Branch 1 not taken.
13824 if (!p_iputw(bst->comb[j], f))
8200 new_return(26);
8201
1/2
✓ Branch 0 taken 13824 times.
✗ Branch 1 not taken.
13824 if (!p_putc(bst->cset[j], f))
8202 new_return(26);
8203
1/2
✓ Branch 0 taken 13824 times.
✗ Branch 1 not taken.
13824 if (!p_iputw(bst->price[j], f))
8204 new_return(26);
8205
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 13824 times.
13824 if (!p_iputw(bst->str[j], f))
8206 new_return(26);
8207 13824 }
8208 4608 }
8209
8210 //V_MISC >= 14
8211
2/2
✓ Branch 0 taken 4608 times.
✓ Branch 1 taken 18 times.
4626 for(int32_t q = 0; q < sfxMAX; ++q)
8212 {
8213
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(QMisc.miscsfx[q],f))
8214 new_return(27);
8215 4608 }
8216
8217 //V_MISC >= 17
8218 18 byte save_menu_count = 0;
8219
2/2
✓ Branch 0 taken 576 times.
✓ Branch 1 taken 18 times.
594 for(size_t q = 0; q < NUM_SAVE_MENUS; ++q)
8220
1/2
✓ Branch 0 taken 576 times.
✗ Branch 1 not taken.
576 if (!QMisc.save_menus[q].is_empty())
8221 save_menu_count = q+1;
8222
8223
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (!p_putc(save_menu_count, f))
8224 new_return(28);
8225
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 for(size_t q = 0; q < save_menu_count; ++q)
8226 {
8227 SaveMenu const& menu = QMisc.save_menus[q];
8228
8229 byte empty = menu.is_empty() ? 1 : 0;
8230
8231 if (!p_putc(empty, f))
8232 new_return(29);
8233 if (empty) continue;
8234
8235 if (!p_putcstr(menu.name, f))
8236 new_return(30);
8237
8238 if (!p_iputw(menu.flags, f))
8239 new_return(31);
8240
8241 if (!p_iputl(menu.cursor_tile, f))
8242 new_return(32);
8243
8244 if (!p_putc(menu.cursor_cset, f))
8245 new_return(33);
8246
8247 if (!p_putc(menu.cursor_sfx, f))
8248 new_return(34);
8249
8250 if (!p_putc(menu.choose_sfx, f))
8251 new_return(35);
8252
8253 if (!p_putc(menu.bg_color, f))
8254 new_return(36);
8255
8256 if (!p_putc(menu.hspace, f))
8257 new_return(37);
8258
8259 if (!p_putc(menu.vspace, f))
8260 new_return(38);
8261
8262 if (!p_putc(menu.opt_x, f))
8263 new_return(39);
8264
8265 if (!p_putc(menu.opt_y, f))
8266 new_return(40);
8267
8268 if (!p_putc(menu.text_align, f))
8269 new_return(41);
8270
8271 if (!p_putc(menu.textbox_align, f))
8272 new_return(42);
8273
8274 if (!p_iputw(menu.close_frames, f))
8275 new_return(43);
8276
8277 if (!p_putc(menu.close_flash_rate, f))
8278 new_return(44);
8279
8280 if (!p_iputw(menu.midi, f))
8281 new_return(45);
8282
8283 if (!p_iputl(menu.bg_tile, f))
8284 new_return(46);
8285
8286 if (!p_putc(menu.bg_cset, f))
8287 new_return(47);
8288
8289 if (!p_putc(menu.bg_tw, f))
8290 new_return(48);
8291
8292 if (!p_putc(menu.bg_th, f))
8293 new_return(49);
8294
8295 byte opt_count = zc_min(menu.options.size(), MAX_SAVEMENU_OPTIONS);
8296 if (!p_putc(opt_count, f))
8297 new_return(50);
8298
8299 for (size_t q = 0; q < opt_count; ++q)
8300 {
8301 SaveMenuOption const& opt = menu.options[q];
8302
8303 if (!p_putcstr(opt.text, f))
8304 new_return(51);
8305
8306 if (!p_iputw(opt.flags, f))
8307 new_return(52);
8308
8309 if (!p_putc(opt.color, f))
8310 new_return(53);
8311
8312 if (!p_putc(opt.picked_color, f))
8313 new_return(54);
8314
8315 if (!p_iputl(opt.font, f))
8316 new_return(55);
8317
8318 if (!p_iputw(opt.gen_script, f))
8319 new_return(56);
8320 }
8321 }
8322
8323
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (!p_putc(QMisc.savemenu_game_over, f))
8324 new_return(57);
8325
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (!p_putc(QMisc.savemenu_f6, f))
8326 new_return(58);
8327
8328
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
8329 {
8330 9 section_size=writesize;
8331 9 }
8332 18 }
8333
8334
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
8335 {
8336 char ebuf[80];
8337 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
8338 jwin_alert("Error: writemisc()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
8339 }
8340
8341 9 new_return(0);
8342 }
8343
8344 9 int32_t writeitems(PACKFILE *f, zquestheader *Header)
8345 {
8346 //these are here to bypass compiler warnings about unused arguments
8347 9 Header=Header;
8348
8349 9 dword section_id=ID_ITEMS;
8350 9 dword section_version=V_ITEMS;
8351 // dword section_size=0;
8352 9 dword section_size = 0;
8353
8354 //section id
8355
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
8356 {
8357 new_return(1);
8358 }
8359
8360 //section version info
8361
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
8362 {
8363 new_return(2);
8364 }
8365
8366
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!write_deprecated_section_cversion(section_version,f))
8367 {
8368 new_return(3);
8369 }
8370
8371
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
8372 {
8373 18 fake_pack_writing=(writecycle==0);
8374
8375 //section size
8376
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
8377 {
8378 new_return(4);
8379 }
8380
8381 18 writesize=0;
8382
8383 //finally... section data
8384
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(MAXITEMS,f))
8385 {
8386 new_return(5);
8387 }
8388
8389
2/2
✓ Branch 0 taken 4608 times.
✓ Branch 1 taken 18 times.
4626 for(int32_t i=0; i<MAXITEMS; i++)
8390 {
8391
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!pfwrite(item_string[i], 64, f))
8392 {
8393 new_return(5);
8394 }
8395 4608 }
8396
8397
2/2
✓ Branch 0 taken 4608 times.
✓ Branch 1 taken 18 times.
4626 for(int32_t i=0; i<MAXITEMS; i++)
8398 {
8399
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].tile,f))
8400 {
8401 new_return(6);
8402 }
8403
8404
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].misc_flags,f))
8405 {
8406 new_return(7);
8407 }
8408
8409
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].csets,f))
8410 {
8411 new_return(8);
8412 }
8413
8414
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].frames,f))
8415 {
8416 new_return(9);
8417 }
8418
8419
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].speed,f))
8420 {
8421 new_return(10);
8422 }
8423
8424
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].delay,f))
8425 {
8426 new_return(11);
8427 }
8428
8429
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].ltm,f))
8430 {
8431 new_return(12);
8432 }
8433
8434
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].type,f))
8435 {
8436 new_return(13);
8437 }
8438
8439
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].level,f))
8440 {
8441 new_return(14);
8442 }
8443
8444
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].power,f))
8445 {
8446 new_return(14);
8447 }
8448
8449
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].flags,f))
8450 {
8451 new_return(15);
8452 }
8453
8454
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputw(itemsbuf[i].script,f))
8455 {
8456 new_return(16);
8457 }
8458
8459
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].count,f))
8460 {
8461 new_return(17);
8462 }
8463
8464
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputw(itemsbuf[i].amount,f))
8465 {
8466 new_return(18);
8467 }
8468
8469
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputw(itemsbuf[i].collect_script,f))
8470 {
8471 new_return(19);
8472 }
8473
8474
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputw(itemsbuf[i].setmax,f))
8475 {
8476 new_return(21);
8477 }
8478
8479
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputw(itemsbuf[i].max,f))
8480 {
8481 new_return(22);
8482 }
8483
8484
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].playsound,f))
8485 {
8486 new_return(23);
8487 }
8488
8489
2/2
✓ Branch 0 taken 36864 times.
✓ Branch 1 taken 4608 times.
41472 for(int32_t j=0; j<8; j++)
8490 {
8491
1/2
✓ Branch 0 taken 36864 times.
✗ Branch 1 not taken.
36864 if(!p_iputl(itemsbuf[i].initiald[j],f))
8492 {
8493 new_return(24);
8494 }
8495 36864 }
8496
8497
2/2
✓ Branch 0 taken 9216 times.
✓ Branch 1 taken 4608 times.
13824 for(int32_t j=0; j<2; j++)
8498 {
8499
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(0,f))
8500 {
8501 new_return(25);
8502 }
8503 9216 }
8504
8505
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].wpn,f))
8506 {
8507 new_return(26);
8508 }
8509
8510
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].wpn2,f))
8511 {
8512 new_return(27);
8513 }
8514
8515
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4608 times.
4608 if(!p_putc(itemsbuf[i].wpn3,f))
8516 {
8517 new_return(28);
8518 }
8519
8520
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].wpn4,f))
8521 {
8522 new_return(29);
8523 }
8524
8525
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].wpn5,f))
8526 {
8527 new_return(30);
8528 }
8529
8530
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].wpn6,f))
8531 {
8532 new_return(31);
8533 }
8534
8535
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4608 times.
4608 if(!p_putc(itemsbuf[i].wpn7,f))
8536 {
8537 new_return(32);
8538 }
8539
8540
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].wpn8,f))
8541 {
8542 new_return(33);
8543 }
8544
8545
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].wpn9,f))
8546 {
8547 new_return(34);
8548 }
8549
8550
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].wpn10,f))
8551 {
8552 new_return(35);
8553 }
8554
8555
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4608 times.
4608 if(!p_putc(itemsbuf[i].pickup_hearts,f))
8556 {
8557 new_return(36);
8558 }
8559
8560
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].misc1,f))
8561 {
8562 new_return(37);
8563 }
8564
8565
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].misc2,f))
8566 {
8567 new_return(38);
8568 }
8569
8570
2/2
✓ Branch 0 taken 9216 times.
✓ Branch 1 taken 4608 times.
13824 for(auto q = 0; q < 2; ++q)
8571 {
8572
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(itemsbuf[i].cost_amount[q],f))
8573 {
8574 new_return(39);
8575 }
8576 9216 }
8577
8578
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].misc3,f))
8579 {
8580 new_return(40);
8581 }
8582
8583
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].misc4,f))
8584 {
8585 new_return(41);
8586 }
8587
8588
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].misc5,f))
8589 {
8590 new_return(42);
8591 }
8592
8593
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].misc6,f))
8594 {
8595 new_return(43);
8596 }
8597
8598
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].misc7,f))
8599 {
8600 new_return(44);
8601 }
8602
8603
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].misc8,f))
8604 {
8605 new_return(45);
8606 }
8607
8608
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].misc9,f))
8609 {
8610 new_return(46);
8611 }
8612
8613
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].misc10,f))
8614 {
8615 new_return(47);
8616 }
8617
8618
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].usesound,f))
8619 {
8620 new_return(48);
8621 }
8622
8623
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].usesound2,f))
8624 {
8625 new_return(48);
8626 }
8627
8628 //New itemdata vars -Z
8629 //! version 27
8630
8631
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].weaprange,f))
8632 {
8633 new_return(51);
8634 }
8635
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].weapduration,f))
8636 {
8637 new_return(52);
8638 }
8639
2/2
✓ Branch 0 taken 46080 times.
✓ Branch 1 taken 4608 times.
50688 for ( int32_t q = 0; q < ITEM_MOVEMENT_PATTERNS; q++ ) {
8640
1/2
✓ Branch 0 taken 46080 times.
✗ Branch 1 not taken.
46080 if(!p_iputl(itemsbuf[i].weap_pattern[q],f))
8641 {
8642 new_return(53);
8643 }
8644 46080 }
8645 //version 28
8646
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].duplicates,f))
8647 {
8648 new_return(54);
8649 }
8650
2/2
✓ Branch 0 taken 9216 times.
✓ Branch 1 taken 4608 times.
13824 for ( int32_t q = 0; q < 2; q++ )
8651 {
8652
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(0,f))
8653 {
8654 new_return(56);
8655 }
8656 9216 }
8657
8658
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].drawlayer,f))
8659 {
8660 new_return(57);
8661 }
8662
8663
8664
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].hxofs,f))
8665 {
8666 new_return(58);
8667 }
8668
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].hyofs,f))
8669 {
8670 new_return(59);
8671 }
8672
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].hxsz,f))
8673 {
8674 new_return(60);
8675 }
8676
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].hysz,f))
8677 {
8678 new_return(61);
8679 }
8680
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].hzsz,f))
8681 {
8682 new_return(62);
8683 }
8684
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].xofs,f))
8685 {
8686 new_return(63);
8687 }
8688
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].yofs,f))
8689 {
8690 new_return(64);
8691 }
8692
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].wpnsprite,f))
8693 {
8694 new_return(73);
8695 }
8696
2/2
✓ Branch 0 taken 9216 times.
✓ Branch 1 taken 4608 times.
13824 for(auto q = 0; q < 2; ++q)
8697 {
8698
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(itemsbuf[i].magiccosttimer[q],f))
8699 {
8700 new_return(74);
8701 }
8702 9216 }
8703
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].overrideFLAGS,f))
8704 {
8705 new_return(75);
8706 }
8707
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].tilew,f))
8708 {
8709 new_return(76);
8710 }
8711
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].tileh,f))
8712 {
8713 new_return(77);
8714 }
8715
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].pickup,f))
8716 {
8717 new_return(81);
8718 }
8719
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputw(itemsbuf[i].pstring,f))
8720 {
8721 new_return(82);
8722 }
8723
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputw(itemsbuf[i].pickup_string_flags,f))
8724 {
8725 new_return(83);
8726 }
8727
8728
2/2
✓ Branch 0 taken 9216 times.
✓ Branch 1 taken 4608 times.
13824 for(auto q = 0; q < 2; ++q)
8729 {
8730
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(itemsbuf[i].cost_counter[q],f))
8731 {
8732 new_return(84);
8733 }
8734 9216 }
8735
8736 //InitD[] labels
8737
2/2
✓ Branch 0 taken 36864 times.
✓ Branch 1 taken 4608 times.
41472 for ( int32_t q = 0; q < 8; q++ )
8738 {
8739
2/2
✓ Branch 0 taken 2396160 times.
✓ Branch 1 taken 36864 times.
2433024 for ( int32_t w = 0; w < 65; w++ )
8740 {
8741
1/2
✓ Branch 0 taken 2396160 times.
✗ Branch 1 not taken.
2396160 if(!p_putc(itemsbuf[i].initD_label[q][w],f))
8742 {
8743 new_return(85);
8744 }
8745 2396160 }
8746
2/2
✓ Branch 0 taken 2396160 times.
✓ Branch 1 taken 36864 times.
2433024 for ( int32_t w = 0; w < 65; w++ )
8747 {
8748
1/2
✓ Branch 0 taken 2396160 times.
✗ Branch 1 not taken.
2396160 if(!p_putc(itemsbuf[i].sprite_initD_label[q][w],f))
8749 {
8750 new_return(87);
8751 }
8752 2396160 }
8753
1/2
✓ Branch 0 taken 36864 times.
✗ Branch 1 not taken.
36864 if(!p_iputl(itemsbuf[i].sprite_initiald[q],f))
8754 {
8755 new_return(88);
8756 }
8757 36864 }
8758
2/2
✓ Branch 0 taken 9216 times.
✓ Branch 1 taken 4608 times.
13824 for ( int32_t q = 0; q < 2; q++ )
8759 {
8760
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(0,f))
8761 {
8762 new_return(89);
8763 }
8764
8765 9216 }
8766
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputw(itemsbuf[i].sprite_script,f))
8767 {
8768 new_return(90);
8769 }
8770
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].pickupflag,f))
8771 {
8772 new_return(91);
8773 }
8774
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4608 times.
4608 std::string dispname(itemsbuf[i].display_name);
8775
2/4
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 4608 times.
4608 if(!p_putcstr(dispname,f))
8776 new_return(92);
8777
2/4
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4608 times.
✗ Branch 3 not taken.
4608 if(!p_iputw(itemsbuf[i].pickup_litems, f))
8778 new_return(95);
8779
2/4
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4608 times.
✗ Branch 3 not taken.
4608 if(!p_iputw(itemsbuf[i].pickup_litem_level, f))
8780 new_return(96);
8781
2/4
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 4608 times.
4608 if (!p_iputl(itemsbuf[i].moveflags, f))
8782 new_return(97);
8783
2/4
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 4608 times.
4608 if(auto ret = write_weap_data(itemsbuf[i].weap_data, f))
8784 return ret;
8785
2/4
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4608 times.
✗ Branch 3 not taken.
4608 if (!p_iputl(itemsbuf[i].cooldown, f))
8786 new_return(98);
8787
1/3
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✓ Branch 2 taken 4608 times.
4608 }
8788
8789
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
8790 {
8791 9 section_size=writesize;
8792 9 }
8793 18 }
8794
8795
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
8796 {
8797 char ebuf[80];
8798 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
8799 jwin_alert("Error: writeitems()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
8800 }
8801
8802 9 new_return(0);
8803 9 }
8804
8805 9 int32_t writeweapons(PACKFILE *f, zquestheader *Header)
8806 {
8807 //these are here to bypass compiler warnings about unused arguments
8808 9 Header=Header;
8809
8810 9 dword section_id=ID_WEAPONS;
8811 9 dword section_version=V_WEAPONS;
8812 9 dword section_size = 0;
8813
8814 //section id
8815
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
8816 {
8817 new_return(1);
8818 }
8819
8820 //section version info
8821
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
8822 {
8823 new_return(2);
8824 }
8825
8826
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
8827 {
8828 new_return(3);
8829 }
8830
8831
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 18 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
8832 {
8833 18 fake_pack_writing=(writecycle==0);
8834
8835 //section size
8836
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
8837 {
8838 new_return(4);
8839 }
8840
8841 18 writesize=0;
8842
8843 //finally... section data
8844
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(MAXWPNS,f))
8845 {
8846 new_return(5);
8847 }
8848
8849
2/2
✓ Branch 0 taken 4608 times.
✓ Branch 1 taken 18 times.
4626 for(int32_t i=0; i<MAXWPNS; i++)
8850 {
8851
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!pfwrite((char *)weapon_string[i], 64, f))
8852 {
8853 new_return(5);
8854 }
8855 4608 }
8856
8857
2/2
✓ Branch 0 taken 4608 times.
✓ Branch 1 taken 18 times.
4626 for(int32_t i=0; i<MAXWPNS; i++)
8858 {
8859
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(wpnsbuf[i].misc,f))
8860 {
8861 new_return(7);
8862 }
8863
8864
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(wpnsbuf[i].csets,f))
8865 {
8866 new_return(8);
8867 }
8868
8869
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(wpnsbuf[i].frames,f))
8870 {
8871 new_return(9);
8872 }
8873
8874
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(wpnsbuf[i].speed,f))
8875 {
8876 new_return(10);
8877 }
8878
8879
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(wpnsbuf[i].type,f))
8880 {
8881 new_return(11);
8882 }
8883
8884
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputw(wpnsbuf[i].script,f))
8885 {
8886 new_return(12);
8887 }
8888
8889
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(wpnsbuf[i].tile,f))
8890 {
8891 new_return(12);
8892 }
8893 4608 }
8894
8895
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
8896 {
8897 9 section_size=writesize;
8898 9 }
8899 18 }
8900
8901
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
8902 {
8903 char ebuf[80];
8904 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
8905 jwin_alert("Error: writeweapons()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
8906 }
8907
8908 9 new_return(0);
8909 }
8910
8911 12784 int32_t writemapscreen(PACKFILE *f, int32_t i, int32_t j)
8912 {
8913
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12784 times.
12784 if((i*MAPSCRS+j)>=int32_t(TheMaps.size()))
8914 return qe_invalid;
8915
8916 12784 mapscr& screen=TheMaps.at(i*MAPSCRS+j);
8917 12784 bool is_0x80_screen = j >= 0x80;
8918
8919
1/2
✓ Branch 0 taken 12784 times.
✗ Branch 1 not taken.
12784 if(!p_putc(screen.valid,f))
8920 return qe_invalid;
8921
2/2
✓ Branch 0 taken 8380 times.
✓ Branch 1 taken 4404 times.
12784 if(!(screen.valid & mVALID))
8922 4404 return qe_OK;
8923 //Calculate what needs writing
8924 8380 uint32_t scr_has_flags = 0;
8925
4/8
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 8378 times.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
8380 if(screen.guytile || screen.guy || screen.roomflags || screen.str
8926
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
2 || screen.room || screen.catchall)
8927 8380 scr_has_flags |= SCRHAS_ROOMDATA;
8928
7/8
✓ Branch 0 taken 7946 times.
✓ Branch 1 taken 434 times.
✓ Branch 2 taken 192 times.
✓ Branch 3 taken 7754 times.
✓ Branch 4 taken 180 times.
✓ Branch 5 taken 12 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 180 times.
8380 if(screen.hasitem || (is_0x80_screen && (screen.itemx||screen.itemy)))
8929 446 scr_has_flags |= SCRHAS_ITEM;
8930
3/4
✓ Branch 0 taken 8352 times.
✓ Branch 1 taken 28 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 8352 times.
8380 if((screen.warpreturnc&0x00FF) || screen.tilewarpoverlayflags)
8931 28 scr_has_flags |= SCRHAS_TWARP;
8932
2/2
✓ Branch 0 taken 8176 times.
✓ Branch 1 taken 32882 times.
41058 else for(auto q = 0; q < 4; ++q)
8933 {
8934
1/2
✓ Branch 0 taken 32706 times.
✗ Branch 1 not taken.
65588 if(screen.tilewarptype[q]
8935
2/2
✓ Branch 0 taken 32708 times.
✓ Branch 1 taken 174 times.
32882 || screen.tilewarpdmap[q]
8936
2/2
✓ Branch 0 taken 32706 times.
✓ Branch 1 taken 2 times.
32708 || screen.tilewarpscr[q])
8937 {
8938 176 scr_has_flags |= SCRHAS_TWARP;
8939 176 break;
8940 }
8941 32706 }
8942
3/4
✓ Branch 0 taken 8376 times.
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 8344 times.
8380 if((screen.warpreturnc&0xFF00) || screen.sidewarpindex
8943
2/2
✓ Branch 0 taken 8344 times.
✓ Branch 1 taken 32 times.
8376 || screen.sidewarpoverlayflags)
8944 36 scr_has_flags |= SCRHAS_SWARP;
8945
2/2
✓ Branch 0 taken 4074 times.
✓ Branch 1 taken 20568 times.
24642 else for(auto q = 0; q < 4; ++q)
8946 {
8947
2/2
✓ Branch 0 taken 16298 times.
✓ Branch 1 taken 12 times.
36878 if(screen.sidewarptype[q] != wtSCROLL
8948
2/2
✓ Branch 0 taken 16436 times.
✓ Branch 1 taken 4132 times.
20568 || screen.sidewarpdmap[q]
8949
2/2
✓ Branch 0 taken 16310 times.
✓ Branch 1 taken 126 times.
16436 || screen.sidewarpscr[q])
8950 {
8951 4270 scr_has_flags |= SCRHAS_SWARP;
8952 4270 break;
8953 }
8954 16298 }
8955
3/4
✓ Branch 0 taken 8336 times.
✓ Branch 1 taken 44 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 8336 times.
8380 if(screen.warparrivalx || screen.warparrivaly)
8956 44 scr_has_flags |= SCRHAS_WARPRET;
8957
2/2
✓ Branch 0 taken 7552 times.
✓ Branch 1 taken 30992 times.
38544 else for(auto q = 0; q < 4; ++q)
8958 {
8959
4/4
✓ Branch 0 taken 30210 times.
✓ Branch 1 taken 782 times.
✓ Branch 2 taken 30208 times.
✓ Branch 3 taken 2 times.
30992 if(screen.warpreturnx[q] || screen.warpreturny[q])
8960 {
8961 784 scr_has_flags |= SCRHAS_WARPRET;
8962 784 break;
8963 }
8964 30208 }
8965
8966
2/4
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 8380 times.
8380 if(screen.hidelayers || screen.hidescriptlayers)
8967 scr_has_flags |= SCRHAS_LAYERS;
8968
2/2
✓ Branch 0 taken 7414 times.
✓ Branch 1 taken 45498 times.
52912 else for(auto q = 0; q < 6; ++q)
8969 {
8970
4/4
✓ Branch 0 taken 44552 times.
✓ Branch 1 taken 946 times.
✓ Branch 2 taken 44532 times.
✓ Branch 3 taken 20 times.
45498 if(screen.layermap[q] || screen.layerscreen[q]
8971
1/2
✓ Branch 0 taken 44552 times.
✗ Branch 1 not taken.
44552 || screen.layeropacity[q]!=255)
8972 {
8973 966 scr_has_flags |= SCRHAS_LAYERS;
8974 966 break;
8975 }
8976 44532 }
8977
8978
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 8370 times.
8380 if(screen.exitdir)
8979 10 scr_has_flags |= SCRHAS_MAZE;
8980
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8370 times.
8370 else if(screen.maze_transition_wipe)
8981 scr_has_flags |= SCRHAS_MAZE;
8982
2/2
✓ Branch 0 taken 8370 times.
✓ Branch 1 taken 33480 times.
41850 else for(auto q = 0; q < 4; ++q)
8983 {
8984
1/2
✓ Branch 0 taken 33480 times.
✗ Branch 1 not taken.
33480 if(screen.path[q])
8985 {
8986 scr_has_flags |= SCRHAS_MAZE;
8987 break;
8988 }
8989 33480 }
8990
8991
4/4
✓ Branch 0 taken 8146 times.
✓ Branch 1 taken 234 times.
✓ Branch 2 taken 322 times.
✓ Branch 3 taken 5412 times.
14114 if(screen.door_combo_set || screen.stairx
8992
3/4
✓ Branch 0 taken 8118 times.
✓ Branch 1 taken 28 times.
✓ Branch 2 taken 8118 times.
✗ Branch 3 not taken.
8146 || screen.stairy || screen.undercombo
8993
2/2
✓ Branch 0 taken 5734 times.
✓ Branch 1 taken 2384 times.
8118 || screen.undercset)
8994 2968 scr_has_flags |= SCRHAS_D_S_U;
8995
2/2
✓ Branch 0 taken 200 times.
✓ Branch 1 taken 6012 times.
6212 else for(auto q = 0; q < 4; ++q)
8996 {
8997
2/2
✓ Branch 0 taken 800 times.
✓ Branch 1 taken 5212 times.
6012 if(screen.door[q] != dNONE)
8998 {
8999 5212 scr_has_flags |= SCRHAS_D_S_U;
9000 5212 break;
9001 }
9002 800 }
9003
9004
2/2
✓ Branch 0 taken 8076 times.
✓ Branch 1 taken 304 times.
15600 if(screen.flags || screen.flags2
9005
4/4
✓ Branch 0 taken 7830 times.
✓ Branch 1 taken 246 times.
✓ Branch 2 taken 7698 times.
✓ Branch 3 taken 132 times.
8076 || screen.flags3 || screen.flags4
9006
4/4
✓ Branch 0 taken 7684 times.
✓ Branch 1 taken 14 times.
✓ Branch 2 taken 7662 times.
✓ Branch 3 taken 22 times.
7698 || screen.flags5 || screen.flags6
9007
4/4
✓ Branch 0 taken 7448 times.
✓ Branch 1 taken 214 times.
✓ Branch 2 taken 7220 times.
✓ Branch 3 taken 228 times.
7662 || screen.flags7 || screen.flags8
9008
2/4
✓ Branch 0 taken 7220 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 7220 times.
✗ Branch 3 not taken.
7220 || screen.flags9 || screen.flags10
9009
1/2
✓ Branch 0 taken 7220 times.
✗ Branch 1 not taken.
7220 || screen.flags11)
9010 8380 scr_has_flags |= SCRHAS_FLAGS;
9011
9012
2/2
✓ Branch 0 taken 58 times.
✓ Branch 1 taken 8322 times.
8380 if(screen.pattern)
9013 58 scr_has_flags |= SCRHAS_ENEMY;
9014
2/2
✓ Branch 0 taken 7308 times.
✓ Branch 1 taken 74100 times.
81408 else for(auto q = 0; q < 10; ++q)
9015 {
9016
2/2
✓ Branch 0 taken 73086 times.
✓ Branch 1 taken 1014 times.
74100 if(screen.enemy[q])
9017 {
9018 1014 scr_has_flags |= SCRHAS_ENEMY;
9019 1014 break;
9020 }
9021 73086 }
9022
9023
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 8380 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
8380 if(screen.noreset != mDEF_NORESET || screen.nocarry != mDEF_NOCARRYOVER
9024 || screen.nextmap || screen.nextscr || screen.exstate_reset || screen.exstate_carry)
9025 8380 scr_has_flags |= SCRHAS_CARRY;
9026
9027
3/4
✓ Branch 0 taken 8358 times.
✓ Branch 1 taken 22 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 8358 times.
8380 if(screen.script || screen.preloadscript)
9028 22 scr_has_flags |= SCRHAS_SCRIPT;
9029
2/2
✓ Branch 0 taken 8358 times.
✓ Branch 1 taken 66864 times.
75222 else for(auto q = 0; q < 8; ++q)
9030 {
9031
1/2
✓ Branch 0 taken 66864 times.
✗ Branch 1 not taken.
66864 if(screen.screeninitd[q])
9032 {
9033 scr_has_flags |= SCRHAS_SCRIPT;
9034 break;
9035 }
9036 66864 }
9037
9038
2/2
✓ Branch 0 taken 5304 times.
✓ Branch 1 taken 683992 times.
689296 for(auto q = 0; q < 128; ++q)
9039 {
9040
1/2
✓ Branch 0 taken 680916 times.
✗ Branch 1 not taken.
1364908 if(screen.secretcombo[q]
9041
2/2
✓ Branch 0 taken 680922 times.
✓ Branch 1 taken 3070 times.
683992 || screen.secretcset[q]
9042
2/2
✓ Branch 0 taken 680916 times.
✓ Branch 1 taken 6 times.
680922 || screen.secretflag[q])
9043 {
9044 3076 scr_has_flags |= SCRHAS_SECRETS;
9045 3076 break;
9046 }
9047 680916 }
9048
9049
2/2
✓ Branch 0 taken 3020 times.
✓ Branch 1 taken 573892 times.
576912 for(auto q = 0; q < 176; ++q)
9050 {
9051
4/4
✓ Branch 0 taken 568780 times.
✓ Branch 1 taken 5112 times.
✓ Branch 2 taken 568532 times.
✓ Branch 3 taken 12 times.
573892 if(screen.data[q] || screen.cset[q]
9052
2/2
✓ Branch 0 taken 568544 times.
✓ Branch 1 taken 236 times.
568780 || screen.sflag[q])
9053 {
9054 5360 scr_has_flags |= SCRHAS_COMBOFLAG;
9055 5360 break;
9056 }
9057 568532 }
9058
9059
2/2
✓ Branch 0 taken 6144 times.
✓ Branch 1 taken 2236 times.
8380 if(screen.color || screen.csensitive != 1
9060
3/4
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6110 times.
✓ Branch 3 taken 34 times.
6144 || screen.oceansfx || screen.bosssfx
9061
2/4
✓ Branch 0 taken 6110 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 6110 times.
6110 || screen.secretsfx || screen.holdupsfx
9062 || screen.timedwarptics || screen.screen_midi != -1
9063 || screen.lens_layer || screen.lens_show || screen.lens_hide)
9064 8380 scr_has_flags |= SCRHAS_MISC;
9065
9066
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_iputl(scr_has_flags,f))
9067 return qe_invalid;
9068
9069 //Write stuff
9070
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8380 times.
8380 if(scr_has_flags & SCRHAS_ROOMDATA)
9071 {
9072
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_putc(screen.guy,f))
9073 return qe_invalid;
9074
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_iputl(screen.guytile,f))
9075 return qe_invalid;
9076
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_putc(screen.guycs,f))
9077 return qe_invalid;
9078
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_iputw(screen.roomflags,f))
9079 return qe_invalid;
9080
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_iputw(screen.str,f))
9081 return qe_invalid;
9082
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_putc(screen.room,f))
9083 return qe_invalid;
9084
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_iputw(screen.catchall,f))
9085 return qe_invalid;
9086 8380 }
9087
2/2
✓ Branch 0 taken 7934 times.
✓ Branch 1 taken 446 times.
8380 if(scr_has_flags & SCRHAS_ITEM)
9088 {
9089
1/2
✓ Branch 0 taken 446 times.
✗ Branch 1 not taken.
446 if(!p_putc(screen.item,f))
9090 return qe_invalid;
9091
1/2
✓ Branch 0 taken 446 times.
✗ Branch 1 not taken.
446 if(!p_putc(screen.hasitem,f))
9092 return qe_invalid;
9093
1/2
✓ Branch 0 taken 446 times.
✗ Branch 1 not taken.
446 if(!p_putc(screen.itemx,f))
9094 return qe_invalid;
9095
1/2
✓ Branch 0 taken 446 times.
✗ Branch 1 not taken.
446 if(!p_putc(screen.itemy,f))
9096 return qe_invalid;
9097 446 }
9098
2/2
✓ Branch 0 taken 4006 times.
✓ Branch 1 taken 4374 times.
8380 if(scr_has_flags & (SCRHAS_SWARP|SCRHAS_TWARP))
9099 {
9100
1/2
✓ Branch 0 taken 4374 times.
✗ Branch 1 not taken.
4374 if(!p_iputw(screen.warpreturnc,f))
9101 return qe_invalid;
9102 4374 }
9103
2/2
✓ Branch 0 taken 8176 times.
✓ Branch 1 taken 204 times.
8380 if(scr_has_flags & SCRHAS_TWARP)
9104 {
9105
2/2
✓ Branch 0 taken 816 times.
✓ Branch 1 taken 204 times.
1020 for(int32_t k=0; k<4; k++)
9106 {
9107
1/2
✓ Branch 0 taken 816 times.
✗ Branch 1 not taken.
816 if(!p_putc(screen.tilewarptype[k],f))
9108 return qe_invalid;
9109 816 }
9110
2/2
✓ Branch 0 taken 816 times.
✓ Branch 1 taken 204 times.
1020 for(int32_t k=0; k<4; k++)
9111 {
9112
1/2
✓ Branch 0 taken 816 times.
✗ Branch 1 not taken.
816 if(!p_iputw(screen.tilewarpdmap[k],f))
9113 return qe_invalid;
9114 816 }
9115
9116
2/2
✓ Branch 0 taken 816 times.
✓ Branch 1 taken 204 times.
1020 for(int32_t k=0; k<4; k++)
9117 {
9118
1/2
✓ Branch 0 taken 816 times.
✗ Branch 1 not taken.
816 if(!p_putc(screen.tilewarpscr[k],f))
9119 return qe_invalid;
9120 816 }
9121
9122
1/2
✓ Branch 0 taken 204 times.
✗ Branch 1 not taken.
204 if(!p_putc(screen.tilewarpoverlayflags,f))
9123 return qe_invalid;
9124 204 }
9125
2/2
✓ Branch 0 taken 4074 times.
✓ Branch 1 taken 4306 times.
8380 if(scr_has_flags & SCRHAS_SWARP)
9126 {
9127
2/2
✓ Branch 0 taken 17224 times.
✓ Branch 1 taken 4306 times.
21530 for(int32_t k=0; k<4; k++)
9128 {
9129
1/2
✓ Branch 0 taken 17224 times.
✗ Branch 1 not taken.
17224 if(!p_putc(screen.sidewarptype[k],f))
9130 return qe_invalid;
9131 17224 }
9132
2/2
✓ Branch 0 taken 17224 times.
✓ Branch 1 taken 4306 times.
21530 for(int32_t k=0; k<4; k++)
9133 {
9134
1/2
✓ Branch 0 taken 17224 times.
✗ Branch 1 not taken.
17224 if(!p_iputw(screen.sidewarpdmap[k],f))
9135 return qe_invalid;
9136 17224 }
9137
9138
2/2
✓ Branch 0 taken 17224 times.
✓ Branch 1 taken 4306 times.
21530 for(int32_t k=0; k<4; k++)
9139 {
9140
1/2
✓ Branch 0 taken 17224 times.
✗ Branch 1 not taken.
17224 if(!p_putc(screen.sidewarpscr[k],f))
9141 return qe_invalid;
9142 17224 }
9143
9144
1/2
✓ Branch 0 taken 4306 times.
✗ Branch 1 not taken.
4306 if(!p_putc(screen.sidewarpoverlayflags,f))
9145 return qe_invalid;
9146
1/2
✓ Branch 0 taken 4306 times.
✗ Branch 1 not taken.
4306 if(!p_putc(screen.sidewarpindex,f))
9147 return qe_invalid;
9148 4306 }
9149
2/2
✓ Branch 0 taken 7552 times.
✓ Branch 1 taken 828 times.
8380 if(scr_has_flags & SCRHAS_WARPRET)
9150 {
9151
2/2
✓ Branch 0 taken 3312 times.
✓ Branch 1 taken 828 times.
4140 for(int32_t k=0; k<4; k++)
9152 {
9153
1/2
✓ Branch 0 taken 3312 times.
✗ Branch 1 not taken.
3312 if(!p_putc(screen.warpreturnx[k],f))
9154 return qe_invalid;
9155 3312 }
9156
2/2
✓ Branch 0 taken 3312 times.
✓ Branch 1 taken 828 times.
4140 for(int32_t k=0; k<4; k++)
9157 {
9158
1/2
✓ Branch 0 taken 3312 times.
✗ Branch 1 not taken.
3312 if(!p_putc(screen.warpreturny[k],f))
9159 return qe_invalid;
9160 3312 }
9161
1/2
✓ Branch 0 taken 828 times.
✗ Branch 1 not taken.
828 if(!p_putc(screen.warparrivalx,f))
9162 return qe_invalid;
9163
1/2
✓ Branch 0 taken 828 times.
✗ Branch 1 not taken.
828 if(!p_putc(screen.warparrivaly,f))
9164 return qe_invalid;
9165 828 }
9166
2/2
✓ Branch 0 taken 7414 times.
✓ Branch 1 taken 966 times.
8380 if(scr_has_flags & SCRHAS_LAYERS)
9167 {
9168
2/2
✓ Branch 0 taken 5796 times.
✓ Branch 1 taken 966 times.
6762 for(int32_t k=0; k<6; k++)
9169 {
9170
1/2
✓ Branch 0 taken 5796 times.
✗ Branch 1 not taken.
5796 if(!p_putc(screen.layermap[k],f))
9171 return qe_invalid;
9172 5796 }
9173
2/2
✓ Branch 0 taken 5796 times.
✓ Branch 1 taken 966 times.
6762 for(int32_t k=0; k<6; k++)
9174 {
9175
1/2
✓ Branch 0 taken 5796 times.
✗ Branch 1 not taken.
5796 if(!p_putc(screen.layerscreen[k],f))
9176 return qe_invalid;
9177 5796 }
9178
2/2
✓ Branch 0 taken 5796 times.
✓ Branch 1 taken 966 times.
6762 for(int32_t k=0; k<6; k++)
9179 {
9180
1/2
✓ Branch 0 taken 5796 times.
✗ Branch 1 not taken.
5796 if(!p_putc(screen.layeropacity[k],f))
9181 return qe_invalid;
9182 5796 }
9183
1/2
✓ Branch 0 taken 966 times.
✗ Branch 1 not taken.
966 if(!p_putc(screen.hidelayers,f))
9184 return qe_invalid;
9185
1/2
✓ Branch 0 taken 966 times.
✗ Branch 1 not taken.
966 if(!p_putc(screen.hidescriptlayers,f))
9186 return qe_invalid;
9187 966 }
9188
2/2
✓ Branch 0 taken 8370 times.
✓ Branch 1 taken 10 times.
8380 if(scr_has_flags & SCRHAS_MAZE)
9189 {
9190
2/2
✓ Branch 0 taken 40 times.
✓ Branch 1 taken 10 times.
50 for(int32_t k=0; k<4; k++)
9191 {
9192
1/2
✓ Branch 0 taken 40 times.
✗ Branch 1 not taken.
40 if(!p_putc(screen.path[k],f))
9193 return qe_invalid;
9194 40 }
9195
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 if(!p_putc(screen.exitdir,f))
9196 return qe_invalid;
9197
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 if(!p_putc(screen.maze_transition_wipe,f))
9198 return qe_invalid;
9199 10 }
9200
2/2
✓ Branch 0 taken 200 times.
✓ Branch 1 taken 8180 times.
8380 if(scr_has_flags & SCRHAS_D_S_U)
9201 {
9202
1/2
✓ Branch 0 taken 8180 times.
✗ Branch 1 not taken.
8180 if(!p_iputw(screen.door_combo_set,f))
9203 return qe_invalid;
9204
2/2
✓ Branch 0 taken 32720 times.
✓ Branch 1 taken 8180 times.
40900 for(int32_t k=0; k<4; k++)
9205 {
9206
1/2
✓ Branch 0 taken 32720 times.
✗ Branch 1 not taken.
32720 if(!p_putc(screen.door[k],f))
9207 return qe_invalid;
9208 32720 }
9209
1/2
✓ Branch 0 taken 8180 times.
✗ Branch 1 not taken.
8180 if(!p_putc(screen.stairx,f))
9210 return qe_invalid;
9211
1/2
✓ Branch 0 taken 8180 times.
✗ Branch 1 not taken.
8180 if(!p_putc(screen.stairy,f))
9212 return qe_invalid;
9213
1/2
✓ Branch 0 taken 8180 times.
✗ Branch 1 not taken.
8180 if(!p_iputw(screen.undercombo,f))
9214 return qe_invalid;
9215
1/2
✓ Branch 0 taken 8180 times.
✗ Branch 1 not taken.
8180 if(!p_putc(screen.undercset,f))
9216 return qe_invalid;
9217 8180 }
9218
2/2
✓ Branch 0 taken 7086 times.
✓ Branch 1 taken 1294 times.
8380 if(scr_has_flags & SCRHAS_FLAGS)
9219 {
9220
1/2
✓ Branch 0 taken 1294 times.
✗ Branch 1 not taken.
1294 if(!p_putc(screen.flags,f))
9221 return qe_invalid;
9222
1/2
✓ Branch 0 taken 1294 times.
✗ Branch 1 not taken.
1294 if(!p_putc(screen.flags2,f))
9223 return qe_invalid;
9224
1/2
✓ Branch 0 taken 1294 times.
✗ Branch 1 not taken.
1294 if(!p_putc(screen.flags3,f))
9225 return qe_invalid;
9226
1/2
✓ Branch 0 taken 1294 times.
✗ Branch 1 not taken.
1294 if(!p_putc(screen.flags4,f))
9227 return qe_invalid;
9228
1/2
✓ Branch 0 taken 1294 times.
✗ Branch 1 not taken.
1294 if(!p_putc(screen.flags5,f))
9229 return qe_invalid;
9230
1/2
✓ Branch 0 taken 1294 times.
✗ Branch 1 not taken.
1294 if(!p_putc(screen.flags6,f))
9231 return qe_invalid;
9232
1/2
✓ Branch 0 taken 1294 times.
✗ Branch 1 not taken.
1294 if(!p_putc(screen.flags7,f))
9233 return qe_invalid;
9234
1/2
✓ Branch 0 taken 1294 times.
✗ Branch 1 not taken.
1294 if(!p_putc(screen.flags8,f))
9235 return qe_invalid;
9236
1/2
✓ Branch 0 taken 1294 times.
✗ Branch 1 not taken.
1294 if(!p_putc(screen.flags9,f))
9237 return qe_invalid;
9238
1/2
✓ Branch 0 taken 1294 times.
✗ Branch 1 not taken.
1294 if(!p_putc(screen.flags10,f))
9239 return qe_invalid;
9240
1/2
✓ Branch 0 taken 1294 times.
✗ Branch 1 not taken.
1294 if(!p_putc(screen.flags11,f))
9241 return qe_invalid;
9242 1294 }
9243
2/2
✓ Branch 0 taken 7308 times.
✓ Branch 1 taken 1072 times.
8380 if(scr_has_flags & SCRHAS_ENEMY)
9244 {
9245
2/2
✓ Branch 0 taken 10720 times.
✓ Branch 1 taken 1072 times.
11792 for(int32_t k=0; k<10; k++)
9246 {
9247
1/2
✓ Branch 0 taken 10720 times.
✗ Branch 1 not taken.
10720 if(!p_iputw(screen.enemy[k],f))
9248 return qe_invalid;
9249 10720 }
9250
1/2
✓ Branch 0 taken 1072 times.
✗ Branch 1 not taken.
1072 if(!p_putc(screen.pattern,f))
9251 return qe_invalid;
9252 1072 }
9253
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8380 times.
8380 if(scr_has_flags & SCRHAS_CARRY)
9254 {
9255
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_iputl(screen.noreset,f))
9256 return qe_invalid;
9257
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_iputl(screen.nocarry,f))
9258 return qe_invalid;
9259
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_iputl(screen.exstate_reset,f))
9260 return qe_invalid;
9261
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_iputl(screen.exstate_carry,f))
9262 return qe_invalid;
9263
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_putc(screen.nextmap,f))
9264 return qe_invalid;
9265
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_putc(screen.nextscr,f))
9266 return qe_invalid;
9267 8380 }
9268
2/2
✓ Branch 0 taken 8358 times.
✓ Branch 1 taken 22 times.
8380 if(scr_has_flags & SCRHAS_SCRIPT)
9269 {
9270
1/2
✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
22 if(!p_iputw(screen.script,f))
9271 return qe_invalid;
9272
1/2
✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
22 if(!p_putc(screen.preloadscript,f))
9273 return qe_invalid;
9274
2/2
✓ Branch 0 taken 176 times.
✓ Branch 1 taken 22 times.
198 for ( int32_t q = 0; q < 8; q++ )
9275 {
9276
1/2
✓ Branch 0 taken 176 times.
✗ Branch 1 not taken.
176 if(!p_iputl(screen.screeninitd[q],f))
9277 return qe_invalid;
9278 176 }
9279 22 }
9280
2/2
✓ Branch 0 taken 5304 times.
✓ Branch 1 taken 3076 times.
8380 if(scr_has_flags & SCRHAS_SECRETS)
9281 {
9282
2/2
✓ Branch 0 taken 393728 times.
✓ Branch 1 taken 3076 times.
396804 for(int32_t k=0; k<128; k++)
9283 {
9284
1/2
✓ Branch 0 taken 393728 times.
✗ Branch 1 not taken.
393728 if(!p_iputw(screen.secretcombo[k],f))
9285 return qe_invalid;
9286 393728 }
9287
9288
2/2
✓ Branch 0 taken 393728 times.
✓ Branch 1 taken 3076 times.
396804 for(int32_t k=0; k<128; k++)
9289 {
9290
1/2
✓ Branch 0 taken 393728 times.
✗ Branch 1 not taken.
393728 if(!p_putc(screen.secretcset[k],f))
9291 return qe_invalid;
9292 393728 }
9293
9294
2/2
✓ Branch 0 taken 393728 times.
✓ Branch 1 taken 3076 times.
396804 for(int32_t k=0; k<128; k++)
9295 {
9296
1/2
✓ Branch 0 taken 393728 times.
✗ Branch 1 not taken.
393728 if(!p_putc(screen.secretflag[k],f))
9297 return qe_invalid;
9298 393728 }
9299 3076 }
9300
2/2
✓ Branch 0 taken 3020 times.
✓ Branch 1 taken 5360 times.
8380 if(scr_has_flags & SCRHAS_COMBOFLAG)
9301 {
9302
2/2
✓ Branch 0 taken 943360 times.
✓ Branch 1 taken 5360 times.
948720 for(int32_t k=0; k<176; ++k)
9303 {
9304
1/2
✓ Branch 0 taken 943360 times.
✗ Branch 1 not taken.
943360 if(!p_iputw(screen.data[k],f))
9305 return qe_invalid;
9306 943360 }
9307
2/2
✓ Branch 0 taken 943360 times.
✓ Branch 1 taken 5360 times.
948720 for(int32_t k=0; k<176; ++k)
9308 {
9309
1/2
✓ Branch 0 taken 943360 times.
✗ Branch 1 not taken.
943360 if(!p_putc(screen.sflag[k],f))
9310 return qe_invalid;
9311 943360 }
9312
2/2
✓ Branch 0 taken 943360 times.
✓ Branch 1 taken 5360 times.
948720 for(int32_t k=0; k<176; ++k)
9313 {
9314
1/2
✓ Branch 0 taken 943360 times.
✗ Branch 1 not taken.
943360 if(!p_putc(screen.cset[k],f))
9315 return qe_invalid;
9316 943360 }
9317 5360 }
9318
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8380 times.
8380 if(scr_has_flags & SCRHAS_MISC)
9319 {
9320
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_iputw(screen.color,f))
9321 return qe_invalid;
9322
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_putc(screen.csensitive,f))
9323 return qe_invalid;
9324
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_putc(screen.oceansfx,f))
9325 return qe_invalid;
9326
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_putc(screen.bosssfx,f))
9327 return qe_invalid;
9328
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_putc(screen.secretsfx,f))
9329 return qe_invalid;
9330
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_putc(screen.holdupsfx,f))
9331 return qe_invalid;
9332
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_iputw(screen.timedwarptics,f))
9333 return qe_invalid;
9334
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_iputw(screen.screen_midi,f))
9335 return qe_invalid;
9336
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_putc(screen.lens_layer,f))
9337 return qe_invalid;
9338
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8380 times.
8380 if(!p_putc(screen.lens_show,f))
9339 return qe_invalid;
9340
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_putc(screen.lens_hide,f))
9341 return qe_invalid;
9342 8380 }
9343
9344 8380 dword numffc = screen.numFFC();
9345
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_iputw(numffc,f))
9346 return qe_invalid;
9347
2/2
✓ Branch 0 taken 245678 times.
✓ Branch 1 taken 8380 times.
254058 for(int32_t k=0; k<numffc; ++k)
9348 {
9349 245678 ffcdata const& tempffc = screen.ffcs[k];
9350
9351
1/2
✓ Branch 0 taken 245678 times.
✗ Branch 1 not taken.
245678 if(!p_iputw(tempffc.data,f))
9352 return qe_invalid;
9353
9354
2/2
✓ Branch 0 taken 2314 times.
✓ Branch 1 taken 243364 times.
245678 if(!tempffc.data) //don't save the rest of the ffc
9355 243364 continue;
9356
9357
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_putc(tempffc.cset,f))
9358 return qe_invalid;
9359
9360
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_iputw(tempffc.delay,f))
9361 return qe_invalid;
9362
9363
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_iputzf(tempffc.x,f))
9364 return qe_invalid;
9365
9366
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_iputzf(tempffc.y,f))
9367 return qe_invalid;
9368
9369
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_iputzf(tempffc.vx,f))
9370 return qe_invalid;
9371
9372
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_iputzf(tempffc.vy,f))
9373 return qe_invalid;
9374
9375
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_iputzf(tempffc.ax,f))
9376 return qe_invalid;
9377
9378
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_iputzf(tempffc.ay,f))
9379 return qe_invalid;
9380
9381
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_putc(tempffc.link,f))
9382 return qe_invalid;
9383
9384
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_iputl(tempffc.hit_width,f))
9385 return qe_invalid;
9386
9387
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_iputl(tempffc.hit_height,f))
9388 return qe_invalid;
9389
9390
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_putc(tempffc.txsz,f))
9391 return qe_invalid;
9392
9393
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_putc(tempffc.tysz,f))
9394 return qe_invalid;
9395
9396
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_iputl(tempffc.flags,f))
9397 return qe_invalid;
9398
9399
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_iputw(tempffc.script,f))
9400 return qe_invalid;
9401
9402
2/2
✓ Branch 0 taken 18512 times.
✓ Branch 1 taken 2314 times.
20826 for(auto q = 0; q < 8; ++q)
9403 {
9404
1/2
✓ Branch 0 taken 18512 times.
✗ Branch 1 not taken.
18512 if(!p_iputl(tempffc.initd[q],f))
9405 return qe_invalid;
9406 18512 }
9407
9408
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_putc(tempffc.layer,f))
9409 return qe_invalid;
9410 2314 }
9411
9412
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_putlstr(screen.usr_notes, f))
9413 return qe_invalid;
9414
9415
2/2
✓ Branch 0 taken 8374 times.
✓ Branch 1 taken 6 times.
8380 if (screen.flags10 & fSCREEN_GRAVITY)
9416 {
9417
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if (!p_iputzf(screen.screen_gravity, f))
9418 return qe_invalid;
9419
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if (!p_iputzf(screen.screen_terminal_v, f))
9420 return qe_invalid;
9421 6 }
9422
9423 8380 return qe_OK;
9424 12784 }
9425
9426 9 int32_t writemaps(PACKFILE *f, zquestheader *)
9427 {
9428 9 dword section_id=ID_MAPS;
9429 9 dword section_version=V_MAPS;
9430 9 dword section_size = 0;
9431
9432 //section id
9433
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
9434 {
9435 new_return(1);
9436 }
9437
9438 //section version info
9439
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
9440 {
9441 new_return(2);
9442 }
9443
9444
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
9445 {
9446 new_return(3);
9447 }
9448
9449
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
9450 {
9451 18 fake_pack_writing=(writecycle==0);
9452
9453 //section size
9454
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
9455 {
9456 new_return(4);
9457 }
9458
9459 18 writesize=0;
9460
9461
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(map_count,f))
9462 {
9463 new_return(5);
9464 }
9465 18 map_infos.resize(map_count);
9466
4/4
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 100 times.
✓ Branch 2 taken 100 times.
✓ Branch 3 taken 18 times.
118 for(int32_t i=0; i<map_count && i<MAXMAPS; i++)
9467 {
9468 100 byte valid = 0;
9469
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 1282 times.
1288 for(int32_t j=0; j<MAPSCRS; j++)
9470 {
9471
1/2
✓ Branch 0 taken 1282 times.
✗ Branch 1 not taken.
1282 if((i*MAPSCRS+j)>=int32_t(TheMaps.size()))
9472 break;
9473 1282 mapscr& screen=TheMaps.at(i*MAPSCRS+j);
9474
2/2
✓ Branch 0 taken 94 times.
✓ Branch 1 taken 1188 times.
1282 if (screen.is_valid())
9475 {
9476 94 valid = 1;
9477 94 break;
9478 }
9479 1188 }
9480
1/2
✓ Branch 0 taken 100 times.
✗ Branch 1 not taken.
100 if(!p_putc(valid,f))
9481 {
9482 new_return(6);
9483 }
9484
2/2
✓ Branch 0 taken 94 times.
✓ Branch 1 taken 6 times.
100 if(!valid) continue;
9485
9486 { //per-map info
9487 94 auto const& mapinf = map_infos[i];
9488
2/2
✓ Branch 0 taken 564 times.
✓ Branch 1 taken 94 times.
658 for(int q = 0; q < 6; ++q)
9489 {
9490
1/2
✓ Branch 0 taken 564 times.
✗ Branch 1 not taken.
564 if(!p_iputw(mapinf.autolayers[q],f))
9491 new_return(7);
9492 564 }
9493
1/2
✓ Branch 0 taken 94 times.
✗ Branch 1 not taken.
94 if(!p_iputw(mapinf.autopalette,f))
9494 new_return(9);
9495
9496
9497
2/2
✓ Branch 0 taken 752 times.
✓ Branch 1 taken 94 times.
846 for(int32_t j=0; j<8; j++)
9498 {
9499
2/2
✓ Branch 0 taken 752 times.
✓ Branch 1 taken 6016 times.
6768 for(int32_t k=0; k<8; k++)
9500 {
9501
1/2
✓ Branch 0 taken 6016 times.
✗ Branch 1 not taken.
6016 if(!p_putc(Regions[i].region_ids[j][k],f))
9502 {
9503 new_return(8);
9504 }
9505 6016 }
9506 752 }
9507 }
9508
9509
2/2
✓ Branch 0 taken 12784 times.
✓ Branch 1 taken 94 times.
12878 for(int32_t j=0; j<MAPSCRS; j++)
9510 12784 writemapscreen(f,i,j);
9511 94 }
9512
9513
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
9514 {
9515 9 section_size=writesize;
9516 9 }
9517 18 }
9518
9519
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
9520 {
9521 char ebuf[80];
9522 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
9523 jwin_alert("Error: writemaps()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
9524 }
9525
9526 9 new_return(0);
9527 }
9528
9529 460 int32_t writecombo_triggers_loop(PACKFILE *f, word section_version, combo_trigger const& tmp_trig)
9530 {
9531
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putcstr(tmp_trig.label,f))
9532 return 22;
9533
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putbitstr(tmp_trig.trigger_flags,f))
9534 return 22;
9535
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputl(tmp_trig.triggerlevel,f))
9536 return 23;
9537
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putc(tmp_trig.triggerbtn,f))
9538 return 34;
9539
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putc(tmp_trig.triggeritem,f))
9540 return 35;
9541
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputw(tmp_trig.trigtimer,f))
9542 return 36;
9543
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putc(tmp_trig.trigsfx,f))
9544 return 37;
9545
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputl(tmp_trig.trigchange,f))
9546 return 38;
9547
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputw(tmp_trig.trigprox,f))
9548 return 39;
9549
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputw(tmp_trig.trigctr,f))
9550 return 40;
9551
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputl(tmp_trig.trigctramnt,f))
9552 return 41;
9553
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putc(tmp_trig.triglbeam,f))
9554 return 42;
9555
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putc(tmp_trig.trigcschange,f))
9556 return 43;
9557
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputw(tmp_trig.spawnitem,f))
9558 return 44;
9559
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputw(tmp_trig.spawnenemy,f))
9560 return 45;
9561
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putc(tmp_trig.exstate,f))
9562 return 46;
9563
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputl(tmp_trig.spawnip,f))
9564 return 47;
9565
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putc(tmp_trig.trigcopycat,f))
9566 return 48;
9567
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putc(tmp_trig.trigcooldown,f))
9568 return 49;
9569
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputw(tmp_trig.prompt_cid,f))
9570 return 50;
9571
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putc(tmp_trig.prompt_cs,f))
9572 return 51;
9573
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputw(tmp_trig.prompt_x,f))
9574 return 52;
9575
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputw(tmp_trig.prompt_y,f))
9576 return 53;
9577
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putc(tmp_trig.trig_lstate,f))
9578 return 69;
9579
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putc(tmp_trig.trig_gstate,f))
9580 return 70;
9581
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputl(tmp_trig.trig_statetime,f))
9582 return 71;
9583
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputw(tmp_trig.trig_genscr,f))
9584 return 72;
9585
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putc(tmp_trig.trig_group,f))
9586 return 76;
9587
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputw(tmp_trig.trig_group_val,f))
9588 return 77;
9589
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putc(tmp_trig.exdoor_dir,f))
9590 return 89;
9591
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putc(tmp_trig.exdoor_ind,f))
9592 return 90;
9593
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputw(tmp_trig.trig_levelitems,f))
9594 return 91;
9595
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputw(tmp_trig.trigdmlevel,f))
9596 return 92;
9597
2/2
✓ Branch 0 taken 1380 times.
✓ Branch 1 taken 460 times.
1840 for(int q = 0; q < 3; ++q)
9598
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1380 times.
1380 if(!p_iputw(tmp_trig.trigtint[q],f))
9599 return 93;
9600
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputw(tmp_trig.triglvlpalette,f))
9601 return 94;
9602
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputw(tmp_trig.trigbosspalette,f))
9603 return 95;
9604
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputw(tmp_trig.trigquaketime,f))
9605 return 96;
9606
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputw(tmp_trig.trigwavytime,f))
9607 return 97;
9608
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputw(tmp_trig.trig_swjinxtime,f))
9609 return 98;
9610
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputw(tmp_trig.trig_itmjinxtime,f))
9611 return 99;
9612
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputw(tmp_trig.trig_stuntime,f))
9613 return 100;
9614
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputw(tmp_trig.trig_bunnytime,f))
9615 return 101;
9616
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_putc(tmp_trig.trig_pushtime,f))
9617 return 102;
9618
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if (!p_iputw(tmp_trig.trig_shieldjinxtime, f))
9619 return 103;
9620
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputl(tmp_trig.req_level_state, f))
9621 return 104;
9622
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputl(tmp_trig.unreq_level_state, f))
9623 return 105;
9624
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putbitstr(tmp_trig.req_global_state, f))
9625 return 106;
9626
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_putbitstr(tmp_trig.unreq_global_state, f))
9627 return 107;
9628
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputw(tmp_trig.fail_prompt_cid, f))
9629 return 108;
9630
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_putc(tmp_trig.fail_prompt_cs, f))
9631 return 109;
9632
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputl(tmp_trig.trig_msgstr, f))
9633 return 110;
9634
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputl(tmp_trig.fail_msgstr, f))
9635 return 111;
9636
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputzf(tmp_trig.player_bounce, f))
9637 return 112;
9638
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputzf(tmp_trig.req_player_z, f))
9639 return 113;
9640
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_putc(tmp_trig.req_player_dir, f))
9641 return 114;
9642
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputzf(tmp_trig.dest_player_x, f))
9643 return 115;
9644
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputzf(tmp_trig.dest_player_y, f))
9645 return 116;
9646
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputzf(tmp_trig.dest_player_z, f))
9647 return 117;
9648
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputzf(tmp_trig.req_player_jump, f))
9649 return 118;
9650
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputzf(tmp_trig.req_player_x, f))
9651 return 119;
9652
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputzf(tmp_trig.req_player_y, f))
9653 return 120;
9654
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_putc(tmp_trig.dest_player_dir, f))
9655 return 121;
9656
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputl(tmp_trig.force_ice_combo, f))
9657 return 122;
9658
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputzf(tmp_trig.force_ice_vx, f))
9659 return 123;
9660
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputzf(tmp_trig.force_ice_vy, f))
9661 return 124;
9662
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputzf(tmp_trig.trig_gravity, f))
9663 return 125;
9664
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputzf(tmp_trig.trig_terminal_v, f))
9665 return 126;
9666
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_putbitstr(tmp_trig.req_screen_state, f))
9667 return 127;
9668
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_putbitstr(tmp_trig.unreq_screen_state, f))
9669 return 128;
9670
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_putbitstr(tmp_trig.req_screen_ex_state, f))
9671 return 129;
9672
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_putbitstr(tmp_trig.unreq_screen_ex_state, f))
9673 return 130;
9674
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_putc(tmp_trig.trigstatemap, f))
9675 return 131;
9676
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_putc(tmp_trig.trigstatescreen, f))
9677 return 132;
9678 460 return 0;
9679 460 }
9680 258906 int32_t writecombo_loop(PACKFILE *f, word section_version, newcombo const& tmp_cmb)
9681 {
9682 //Check what needs writing
9683 258906 word combo_has_flags = 0;
9684
2/2
✓ Branch 0 taken 255716 times.
✓ Branch 1 taken 2056150 times.
2311866 for(auto q = 0; q < 8; ++q)
9685 {
9686
4/4
✓ Branch 0 taken 2054470 times.
✓ Branch 1 taken 1680 times.
✓ Branch 2 taken 1028294 times.
✓ Branch 3 taken 1382 times.
3085826 if(tmp_cmb.attribytes[q] || tmp_cmb.attrishorts[q]
9687
4/4
✓ Branch 0 taken 2054342 times.
✓ Branch 1 taken 128 times.
✓ Branch 2 taken 1029676 times.
✓ Branch 3 taken 1024666 times.
2054470 || (q < 4 && tmp_cmb.attributes[q]))
9688 {
9689 3190 combo_has_flags |= CHAS_ATTRIB;
9690 3190 break;
9691 }
9692 2052960 }
9693
2/2
✓ Branch 0 taken 258446 times.
✓ Branch 1 taken 460 times.
258906 if (!tmp_cmb.triggers.empty())
9694 460 combo_has_flags |= CHAS_TRIG;
9695
4/4
✓ Branch 0 taken 258628 times.
✓ Branch 1 taken 278 times.
✓ Branch 2 taken 20 times.
✓ Branch 3 taken 258608 times.
258906 if(tmp_cmb.usrflags || tmp_cmb.genflags)
9696 298 combo_has_flags |= CHAS_FLAG;
9697
6/6
✓ Branch 0 taken 251806 times.
✓ Branch 1 taken 7100 times.
✓ Branch 2 taken 231382 times.
✓ Branch 3 taken 20424 times.
✓ Branch 4 taken 532 times.
✓ Branch 5 taken 230732 times.
490170 if(tmp_cmb.frames || tmp_cmb.speed || tmp_cmb.nextcombo
9698
6/6
✓ Branch 0 taken 231358 times.
✓ Branch 1 taken 24 times.
✓ Branch 2 taken 231320 times.
✓ Branch 3 taken 38 times.
✓ Branch 4 taken 231264 times.
✓ Branch 5 taken 56 times.
231382 || tmp_cmb.nextcset || tmp_cmb.skipanim || tmp_cmb.skipanimy
9699
1/2
✓ Branch 0 taken 231264 times.
✗ Branch 1 not taken.
231264 || tmp_cmb.animflags)
9700 28174 combo_has_flags |= CHAS_ANIM;
9701
3/4
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✓ Branch 3 taken 258900 times.
258906 if(tmp_cmb.script || tmp_cmb.label.size())
9702 6 combo_has_flags |= CHAS_SCRIPT;
9703
2/2
✓ Branch 0 taken 258900 times.
✓ Branch 1 taken 2071200 times.
2330100 else for(auto q = 0; q < 8; ++q)
9704 {
9705
1/2
✓ Branch 0 taken 2071200 times.
✗ Branch 1 not taken.
2071200 if(tmp_cmb.initd[q])
9706 {
9707 combo_has_flags |= CHAS_SCRIPT;
9708 break;
9709 }
9710 2071200 }
9711
5/6
✓ Branch 0 taken 176904 times.
✓ Branch 1 taken 82002 times.
✓ Branch 2 taken 176392 times.
✓ Branch 3 taken 512 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 176392 times.
435298 if(tmp_cmb.o_tile || tmp_cmb.flip || tmp_cmb.walk != 0xF0
9712
2/4
✓ Branch 0 taken 176392 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 176392 times.
✗ Branch 3 not taken.
176392 || tmp_cmb.type || tmp_cmb.csets)
9713 82514 combo_has_flags |= CHAS_BASIC;
9714
3/4
✓ Branch 0 taken 258898 times.
✓ Branch 1 taken 8 times.
✓ Branch 2 taken 258898 times.
✗ Branch 3 not taken.
517802 if(tmp_cmb.liftcmb || tmp_cmb.liftcs || tmp_cmb.liftdmg
9715
3/6
✓ Branch 0 taken 258898 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 258898 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 258898 times.
✗ Branch 5 not taken.
258898 || tmp_cmb.liftlvl || tmp_cmb.liftitm || tmp_cmb.liftflags
9716
4/6
✓ Branch 0 taken 258896 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 258896 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 258896 times.
✗ Branch 5 not taken.
258898 || tmp_cmb.liftgfx || tmp_cmb.liftsprite || tmp_cmb.liftsfx
9717
2/4
✓ Branch 0 taken 258896 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 258896 times.
✗ Branch 3 not taken.
258896 || tmp_cmb.liftundercmb || tmp_cmb.liftundercs
9718
2/4
✓ Branch 0 taken 258896 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 258896 times.
✗ Branch 3 not taken.
258896 || tmp_cmb.liftbreaksprite!=-1 || tmp_cmb.liftbreaksfx
9719
2/4
✓ Branch 0 taken 258896 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 258896 times.
✗ Branch 3 not taken.
258896 || tmp_cmb.lifthei!=8 || tmp_cmb.lifttime!=16
9720
2/4
✓ Branch 0 taken 258896 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 258896 times.
✗ Branch 3 not taken.
258896 || tmp_cmb.lift_parent_item || !tmp_cmb.lift_weap_data.is_blank())
9721 10 combo_has_flags |= CHAS_LIFT;
9722
2/4
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 258906 times.
✗ Branch 3 not taken.
515612 if(tmp_cmb.speed_mult != 1 || tmp_cmb.speed_div != 1 || tmp_cmb.speed_add
9723
7/10
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 258902 times.
✓ Branch 3 taken 4 times.
✓ Branch 4 taken 258898 times.
✓ Branch 5 taken 4 times.
✓ Branch 6 taken 258898 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 258898 times.
✗ Branch 9 not taken.
258906 || tmp_cmb.sfx_appear || tmp_cmb.sfx_disappear || tmp_cmb.sfx_loop || tmp_cmb.sfx_walking || tmp_cmb.sfx_standing
9724
5/10
✓ Branch 0 taken 258898 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 258898 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 258898 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 258898 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 258898 times.
✗ Branch 9 not taken.
258898 || tmp_cmb.spr_appear || tmp_cmb.spr_disappear || tmp_cmb.spr_walking || tmp_cmb.spr_standing || tmp_cmb.sfx_tap
9725
6/10
✓ Branch 0 taken 258898 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 256706 times.
✓ Branch 3 taken 2192 times.
✓ Branch 4 taken 256706 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 256706 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 256706 times.
✗ Branch 9 not taken.
258898 || tmp_cmb.sfx_landing || tmp_cmb.spr_falling || tmp_cmb.spr_drowning || tmp_cmb.spr_lava_drowning || tmp_cmb.sfx_falling
9726
4/8
✓ Branch 0 taken 256706 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 256706 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 256706 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 256706 times.
✗ Branch 7 not taken.
256706 || tmp_cmb.sfx_drowning || tmp_cmb.sfx_lava_drowning || tmp_cmb.z_height || tmp_cmb.z_step_height
9727
1/2
✓ Branch 0 taken 256706 times.
✗ Branch 1 not taken.
256706 || tmp_cmb.dive_under_level)
9728 258906 combo_has_flags |= CHAS_GENERAL;
9729
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!tmp_cmb.misc_weap_data.is_blank())
9730 combo_has_flags |= CHAS_MISC_WEAP_DATA;
9731
9732
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_iputw(combo_has_flags,f))
9733 {
9734 return 50;
9735 }
9736
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!combo_has_flags) return 0; //Valid, done writing
9737 //Write the combo
9738
2/2
✓ Branch 0 taken 176392 times.
✓ Branch 1 taken 82514 times.
258906 if(combo_has_flags&CHAS_BASIC)
9739 {
9740
1/2
✓ Branch 0 taken 82514 times.
✗ Branch 1 not taken.
82514 if(!p_iputl(tmp_cmb.o_tile,f))
9741 return 6;
9742
9743
1/2
✓ Branch 0 taken 82514 times.
✗ Branch 1 not taken.
82514 if(!p_putc(tmp_cmb.flip,f))
9744 return 7;
9745
9746
1/2
✓ Branch 0 taken 82514 times.
✗ Branch 1 not taken.
82514 if(!p_putc(tmp_cmb.walk,f))
9747 return 8;
9748
9749
1/2
✓ Branch 0 taken 82514 times.
✗ Branch 1 not taken.
82514 if(!p_putc(tmp_cmb.type,f))
9750 return 9;
9751
9752
1/2
✓ Branch 0 taken 82514 times.
✗ Branch 1 not taken.
82514 if(!p_putc(tmp_cmb.flag,f))
9753 return 15;
9754
9755
1/2
✓ Branch 0 taken 82514 times.
✗ Branch 1 not taken.
82514 if(!p_putc(tmp_cmb.csets,f))
9756 return 10;
9757 82514 }
9758
2/2
✓ Branch 0 taken 258900 times.
✓ Branch 1 taken 6 times.
258906 if(combo_has_flags&CHAS_SCRIPT)
9759 {
9760 6 p_putcstr(tmp_cmb.label, f);
9761
9762
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(tmp_cmb.script,f))
9763 return 26;
9764
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 6 times.
54 for ( int32_t q = 0; q < 8; q++ )
9765
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(tmp_cmb.initd[q],f))
9766 return 27;
9767 6 }
9768
2/2
✓ Branch 0 taken 230732 times.
✓ Branch 1 taken 28174 times.
258906 if(combo_has_flags&CHAS_ANIM)
9769 {
9770
1/2
✓ Branch 0 taken 28174 times.
✗ Branch 1 not taken.
28174 if(!p_putc(tmp_cmb.frames,f))
9771 return 11;
9772
9773
1/2
✓ Branch 0 taken 28174 times.
✗ Branch 1 not taken.
28174 if(!p_putc(tmp_cmb.speed,f))
9774 return 12;
9775
9776
1/2
✓ Branch 0 taken 28174 times.
✗ Branch 1 not taken.
28174 if(!p_iputw(tmp_cmb.nextcombo,f))
9777 return 13;
9778
9779
1/2
✓ Branch 0 taken 28174 times.
✗ Branch 1 not taken.
28174 if(!p_putc(tmp_cmb.nextcset,f))
9780 return 14;
9781
9782
1/2
✓ Branch 0 taken 28174 times.
✗ Branch 1 not taken.
28174 if(!p_putc(tmp_cmb.skipanim,f))
9783 return 16;
9784
9785
1/2
✓ Branch 0 taken 28174 times.
✗ Branch 1 not taken.
28174 if(!p_putc(tmp_cmb.skipanimy,f))
9786 return 18;
9787
9788
1/2
✓ Branch 0 taken 28174 times.
✗ Branch 1 not taken.
28174 if(!p_putc(tmp_cmb.animflags,f))
9789 return 19;
9790 28174 }
9791
2/2
✓ Branch 0 taken 255716 times.
✓ Branch 1 taken 3190 times.
258906 if(combo_has_flags&CHAS_ATTRIB)
9792 {
9793
2/2
✓ Branch 0 taken 12760 times.
✓ Branch 1 taken 3190 times.
15950 for ( int32_t q = 0; q < 4; q++ )
9794
1/2
✓ Branch 0 taken 12760 times.
✗ Branch 1 not taken.
12760 if(!p_iputl(tmp_cmb.attributes[q],f))
9795 return 20;
9796
2/2
✓ Branch 0 taken 25520 times.
✓ Branch 1 taken 3190 times.
28710 for ( int32_t q = 0; q < 8; q++ )
9797
1/2
✓ Branch 0 taken 25520 times.
✗ Branch 1 not taken.
25520 if(!p_putc(tmp_cmb.attribytes[q],f))
9798 return 25;
9799
2/2
✓ Branch 0 taken 25520 times.
✓ Branch 1 taken 3190 times.
28710 for ( int32_t q = 0; q < 8; q++ ) //I also added attrishorts -Dimi
9800
1/2
✓ Branch 0 taken 25520 times.
✗ Branch 1 not taken.
25520 if(!p_iputw(tmp_cmb.attrishorts[q],f))
9801 return 32;
9802 3190 }
9803
2/2
✓ Branch 0 taken 258608 times.
✓ Branch 1 taken 298 times.
258906 if(combo_has_flags&CHAS_FLAG)
9804 {
9805
1/2
✓ Branch 0 taken 298 times.
✗ Branch 1 not taken.
298 if(!p_iputl(tmp_cmb.usrflags,f))
9806 return 21;
9807
1/2
✓ Branch 0 taken 298 times.
✗ Branch 1 not taken.
298 if(!p_iputw(tmp_cmb.genflags,f))
9808 return 33;
9809 298 }
9810
2/2
✓ Branch 0 taken 258446 times.
✓ Branch 1 taken 460 times.
258906 if(combo_has_flags&CHAS_TRIG)
9811 {
9812
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 byte sz = zc_min(tmp_cmb.triggers.size(), 255);
9813
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_putc(sz,f))
9814 return 34;
9815
2/2
✓ Branch 0 taken 460 times.
✓ Branch 1 taken 460 times.
920 for(byte q = 0; q < sz; ++q)
9816 {
9817 460 auto ret = writecombo_triggers_loop(f, section_version, tmp_cmb.triggers[q]);
9818
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(ret) return ret;
9819 460 }
9820
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_putc(tmp_cmb.only_gentrig,f))
9821 return 35;
9822 460 }
9823
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 258906 times.
258906 if(combo_has_flags&CHAS_LIFT)
9824 {
9825
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_iputw(tmp_cmb.liftcmb,f))
9826 return 54;
9827
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_putc(tmp_cmb.liftcs,f))
9828 return 55;
9829
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_iputw(tmp_cmb.liftundercmb,f))
9830 return 56;
9831
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_putc(tmp_cmb.liftundercs,f))
9832 return 57;
9833
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_putc(tmp_cmb.liftdmg,f))
9834 return 58;
9835
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_putc(tmp_cmb.liftlvl,f))
9836 return 59;
9837
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_putc(tmp_cmb.liftitm,f))
9838 return 60;
9839
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_putc(tmp_cmb.liftflags,f))
9840 return 61;
9841
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_putc(tmp_cmb.liftgfx,f))
9842 return 62;
9843
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_putc(tmp_cmb.liftsprite,f))
9844 return 63;
9845
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_putc(tmp_cmb.liftsfx,f))
9846 return 64;
9847
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_iputw(tmp_cmb.liftbreaksprite,f))
9848 return 65;
9849
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_putc(tmp_cmb.liftbreaksfx,f))
9850 return 66;
9851
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_putc(tmp_cmb.lifthei,f))
9852 return 67;
9853
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_putc(tmp_cmb.lifttime,f))
9854 return 68;
9855
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_putc(tmp_cmb.lift_parent_item,f))
9856 return 78;
9857
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 258906 times.
258906 if(auto ret = write_weap_data(tmp_cmb.lift_weap_data, f))
9858 return ret;
9859 258906 }
9860
2/2
✓ Branch 0 taken 256706 times.
✓ Branch 1 taken 2200 times.
258906 if(combo_has_flags&CHAS_GENERAL)
9861 {
9862
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.speed_mult,f))
9863 return 73;
9864
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.speed_div,f))
9865 return 74;
9866
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_iputzf(tmp_cmb.speed_add,f))
9867 return 75;
9868
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.sfx_appear,f))
9869 return 79;
9870
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.sfx_disappear,f))
9871 return 80;
9872
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.sfx_loop,f))
9873 return 81;
9874
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.sfx_walking,f))
9875 return 82;
9876
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.sfx_standing,f))
9877 return 83;
9878
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.spr_appear,f))
9879 return 84;
9880
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.spr_disappear,f))
9881 return 85;
9882
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.spr_walking,f))
9883 return 86;
9884
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.spr_standing,f))
9885 return 87;
9886
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.sfx_tap,f))
9887 return 88;
9888
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.sfx_landing,f))
9889 return 89;
9890
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.spr_falling,f))
9891 return 90;
9892
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.spr_drowning,f))
9893 return 91;
9894
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.spr_lava_drowning,f))
9895 return 92;
9896
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.sfx_falling,f))
9897 return 93;
9898
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.sfx_drowning,f))
9899 return 94;
9900
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.sfx_lava_drowning,f))
9901 return 95;
9902
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_iputzf(tmp_cmb.z_height,f))
9903 return 96;
9904
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_iputzf(tmp_cmb.z_step_height,f))
9905 return 97;
9906
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2200 times.
2200 if(!p_putc(tmp_cmb.dive_under_level,f))
9907 return 98;
9908 2200 }
9909
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(combo_has_flags&CHAS_MISC_WEAP_DATA)
9910 {
9911 if(auto ret = write_weap_data(tmp_cmb.misc_weap_data, f))
9912 return ret;
9913 }
9914 258906 return 0;
9915 258906 }
9916
9917 9 int32_t writecombos(PACKFILE *f, word version, word build, word start_combo, word max_combos)
9918 {
9919 //these are here to bypass compiler warnings about unused arguments
9920 9 version=version;
9921 9 build=build;
9922
9923 word combos_used;
9924 9 dword section_id=ID_COMBOS;
9925 9 dword section_version=V_COMBOS;
9926 // dword section_size=0;
9927 9 combos_used = count_combos()-start_combo;
9928
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 combos_used = zc_min(combos_used, max_combos);
9929
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 combos_used = zc_min(combos_used, MAXCOMBOS);
9930 9 dword section_size = 0;
9931
9932 //section id
9933
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
9934 {
9935 new_return(1);
9936 }
9937
9938 //section version info
9939
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
9940 {
9941 new_return(2);
9942 }
9943
9944
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!write_deprecated_section_cversion(section_version,f))
9945 {
9946 new_return(3);
9947 }
9948
9949
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
9950 {
9951 18 fake_pack_writing=(writecycle==0);
9952
9953 //section size
9954
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
9955 {
9956 new_return(4);
9957 }
9958
9959 18 writesize=0;
9960
9961 //finally... section data
9962 18 combos_used=count_combos()-start_combo;
9963
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 combos_used=zc_min(combos_used, max_combos);
9964
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 combos_used=zc_min(combos_used, MAXCOMBOS);
9965
9966
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(combos_used,f))
9967 {
9968 new_return(5);
9969 }
9970
9971 18 size_t end_combo = start_combo+combos_used;
9972
2/2
✓ Branch 0 taken 258906 times.
✓ Branch 1 taken 18 times.
258924 for(size_t q = start_combo; q < end_combo; ++q)
9973 {
9974 258906 auto ret = writecombo_loop(f, section_version, combobuf[q]);
9975
1/4
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
258906 if(ret) new_return(ret);
9976 258906 }
9977
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
9978 {
9979 9 section_size=writesize;
9980 9 }
9981 18 }
9982
9983
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
9984 {
9985 char ebuf[80];
9986 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
9987 jwin_alert("Error: writecombos()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
9988 }
9989
9990 9 new_return(0);
9991 9 }
9992
9993 9 int32_t writecomboaliases(PACKFILE *f, word version, word build)
9994 {
9995 //these are here to bypass compiler warnings about unused arguments
9996 9 version=version;
9997 9 build=build;
9998
9999 9 dword section_id=ID_COMBOALIASES;
10000 9 dword section_version=V_COMBOALIASES;
10001 9 dword section_size=0;
10002
10003 //section id
10004
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
10005 {
10006 new_return(1);
10007 }
10008
10009 //section version info
10010
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
10011 {
10012 new_return(2);
10013 }
10014
10015
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
10016 {
10017 new_return(3);
10018 }
10019
10020
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 18 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
10021 {
10022 18 fake_pack_writing=(writecycle==0);
10023
10024 //section size
10025
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
10026 {
10027 new_return(4);
10028 }
10029
10030 18 writesize=0;
10031
10032 //finally... section data
10033
2/2
✓ Branch 0 taken 147456 times.
✓ Branch 1 taken 18 times.
147474 for(int32_t j=0; j<MAXCOMBOALIASES; j++)
10034 {
10035
1/2
✓ Branch 0 taken 147456 times.
✗ Branch 1 not taken.
147456 if(!p_iputw(combo_aliases[j].combo,f))
10036 {
10037 new_return(5);
10038 }
10039
10040
1/2
✓ Branch 0 taken 147456 times.
✗ Branch 1 not taken.
147456 if(!p_putc(combo_aliases[j].cset,f))
10041 {
10042 new_return(6);
10043 }
10044
10045 147456 int32_t count = ((combo_aliases[j].width+1)*(combo_aliases[j].height+1))*(comboa_lmasktotal(combo_aliases[j].layermask)+1);
10046
10047
1/2
✓ Branch 0 taken 147456 times.
✗ Branch 1 not taken.
147456 if(!p_putc(combo_aliases[j].width,f))
10048 {
10049 new_return(7);
10050 }
10051
10052
1/2
✓ Branch 0 taken 147456 times.
✗ Branch 1 not taken.
147456 if(!p_putc(combo_aliases[j].height,f))
10053 {
10054 new_return(8);
10055 }
10056
10057
1/2
✓ Branch 0 taken 147456 times.
✗ Branch 1 not taken.
147456 if(!p_putc(combo_aliases[j].layermask,f))
10058 {
10059 new_return(9);
10060 }
10061
10062
2/2
✓ Branch 0 taken 149596 times.
✓ Branch 1 taken 147456 times.
297052 for(int32_t k=0; k<count; k++)
10063 {
10064
1/2
✓ Branch 0 taken 149596 times.
✗ Branch 1 not taken.
149596 if(!p_iputw(combo_aliases[j].combos[k],f))
10065 {
10066 new_return(10);
10067 }
10068 149596 }
10069
10070
2/2
✓ Branch 0 taken 149596 times.
✓ Branch 1 taken 147456 times.
297052 for(int32_t k=0; k<count; k++)
10071 {
10072
1/2
✓ Branch 0 taken 149596 times.
✗ Branch 1 not taken.
149596 if(!p_putc(combo_aliases[j].csets[k],f))
10073 {
10074 new_return(11);
10075 }
10076 149596 }
10077 147456 }
10078
10079 //Combo pools!
10080 int16_t num_cpools;
10081
2/2
✓ Branch 0 taken 16 times.
✓ Branch 1 taken 147452 times.
147468 for(num_cpools = MAXCOMBOPOOLS-1; num_cpools >= 0; --num_cpools)
10082 {
10083
2/2
✓ Branch 0 taken 147450 times.
✓ Branch 1 taken 2 times.
147452 if(combo_pools[num_cpools].valid()) //found a used pool
10084 {
10085 2 ++num_cpools;
10086 2 break;
10087 }
10088 147450 }
10089
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 16 times.
18 if(num_cpools < 0) num_cpools = 0;
10090
10091
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(num_cpools,f))
10092 {
10093 new_return(12);
10094 }
10095
10096
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 18 times.
24 for(auto cp = 0; cp < num_cpools; ++cp)
10097 {
10098 6 combo_pool const& pool = combo_pools[cp];
10099 6 int32_t num_combos = pool.combos.size();
10100
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputl(num_combos,f))
10101 {
10102 new_return(13);
10103 }
10104
10105
2/2
✓ Branch 0 taken 26 times.
✓ Branch 1 taken 6 times.
32 for(auto q = 0; q < num_combos; ++q)
10106 {
10107 26 cpool_entry const& entry = pool.combos.at(q);
10108
1/2
✓ Branch 0 taken 26 times.
✗ Branch 1 not taken.
26 if(!p_iputl(entry.cid,f))
10109 {
10110 new_return(14);
10111 }
10112
1/2
✓ Branch 0 taken 26 times.
✗ Branch 1 not taken.
26 if(!p_putc(entry.cset,f))
10113 {
10114 new_return(15);
10115 }
10116
1/2
✓ Branch 0 taken 26 times.
✗ Branch 1 not taken.
26 if(!p_iputw(entry.quant,f))
10117 {
10118 new_return(16);
10119 }
10120 26 }
10121 6 }
10122
10123 //Autocombos!
10124 int16_t num_cautos;
10125
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 147456 times.
147474 for (num_cautos = MAXAUTOCOMBOS - 1; num_cautos >= 0; --num_cautos)
10126 {
10127
1/2
✓ Branch 0 taken 147456 times.
✗ Branch 1 not taken.
147456 if (combo_autos[num_cautos].valid()) //found a used autocombo
10128 {
10129 ++num_cautos;
10130 break;
10131 }
10132 147456 }
10133
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 if (num_cautos < 0) num_cautos = 0;
10134
10135
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (!p_iputw(num_cautos, f))
10136 {
10137 new_return(17);
10138 }
10139
10140
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 for (auto ca = 0; ca < num_cautos; ++ca)
10141 {
10142 combo_auto const& cauto = combo_autos[ca];
10143 if (!p_putc(cauto.getType(), f))
10144 {
10145 new_return(18);
10146 }
10147 if (!p_iputl(cauto.getIconDisplay(), f))
10148 {
10149 new_return(19);
10150 }
10151 if (!p_iputl(cauto.getEraseCombo(), f))
10152 {
10153 new_return(20);
10154 }
10155 if (!p_putc(cauto.getFlags(), f))
10156 {
10157 new_return(21);
10158 }
10159 if (!p_putc(cauto.getArg(), f))
10160 {
10161 new_return(22);
10162 }
10163 int32_t num_combos = cauto.combos.size();
10164 if (!p_iputl(num_combos, f))
10165 {
10166 new_return(23);
10167 }
10168
10169 for (auto q = 0; q < num_combos; ++q)
10170 {
10171 autocombo_entry const& entry = cauto.combos.at(q);
10172 if (!p_putc(entry.ctype, f))
10173 {
10174 new_return(24);
10175 }
10176 if (!p_iputl(entry.cid, f))
10177 {
10178 new_return(25);
10179 }
10180 }
10181 }
10182
10183
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
10184 {
10185 9 section_size=writesize;
10186 9 }
10187 18 }
10188
10189
10190
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
10191 {
10192 char ebuf[80];
10193 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
10194 jwin_alert("Error: writecomboaliases()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
10195 }
10196
10197 9 new_return(0);
10198 }
10199
10200 9 int32_t writecolordata(PACKFILE *f, word version, word build, word start_cset, word max_csets)
10201 {
10202 //these are here to bypass compiler warnings about unused arguments
10203 9 version=version;
10204 9 build=build;
10205 9 start_cset=start_cset;
10206 9 max_csets=max_csets;
10207
10208 9 dword section_id=ID_CSETS;
10209 9 dword section_version=V_CSETS;
10210 9 int32_t palcycles = count_palcycles(&QMisc);
10211 // int32_t palcyccount = count_palcycles(&QMisc);
10212 9 dword section_size = 0;
10213
10214 //section id
10215
10216
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
10217 {
10218 new_return(1);
10219 }
10220
10221 //section version info
10222
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
10223 {
10224 new_return(2);
10225 }
10226
10227
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
10228 {
10229 new_return(3);
10230 }
10231
10232
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 18 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
10233 {
10234 18 fake_pack_writing=(writecycle==0);
10235
10236 //section size
10237
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
10238 {
10239 new_return(4);
10240 }
10241
10242 18 writesize=0;
10243
10244 //finally... section data
10245
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(colordata,psTOTAL255,f))
10246 {
10247 new_return(5);
10248 }
10249
10250
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(palnames,MAXLEVELS*PALNAMESIZE,f))
10251 {
10252 new_return(6);
10253 }
10254
10255
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(palcycles,f))
10256 {
10257 new_return(15);
10258 }
10259
10260
2/2
✓ Branch 0 taken 550 times.
✓ Branch 1 taken 18 times.
568 for(int32_t i=0; i<palcycles; i++)
10261 {
10262
2/2
✓ Branch 0 taken 1650 times.
✓ Branch 1 taken 550 times.
2200 for(int32_t j=0; j<3; j++)
10263 {
10264
1/2
✓ Branch 0 taken 1650 times.
✗ Branch 1 not taken.
1650 if(!p_putc(QMisc.cycles[i][j].first,f))
10265 {
10266 new_return(16);
10267 }
10268 1650 }
10269
10270
2/2
✓ Branch 0 taken 1650 times.
✓ Branch 1 taken 550 times.
2200 for(int32_t j=0; j<3; j++)
10271 {
10272
1/2
✓ Branch 0 taken 1650 times.
✗ Branch 1 not taken.
1650 if(!p_putc(QMisc.cycles[i][j].count,f))
10273 {
10274 new_return(17);
10275 }
10276 1650 }
10277
10278
2/2
✓ Branch 0 taken 1650 times.
✓ Branch 1 taken 550 times.
2200 for(int32_t j=0; j<3; j++)
10279 {
10280
1/2
✓ Branch 0 taken 1650 times.
✗ Branch 1 not taken.
1650 if(!p_putc(QMisc.cycles[i][j].speed,f))
10281 {
10282 new_return(18);
10283 }
10284 1650 }
10285 550 }
10286
10287
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
10288 {
10289 9 section_size=writesize;
10290 9 }
10291 18 }
10292
10293
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
10294 {
10295 char ebuf[80];
10296 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
10297 jwin_alert("Error: writecolordata()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
10298 }
10299
10300 9 new_return(0);
10301 }
10302
10303 9 int32_t writestrings(PACKFILE *f, word version, word build, word start_msgstr, word max_msgstrs)
10304 {
10305 //these are here to bypass compiler warnings about unused arguments
10306 9 version=version;
10307 9 build=build;
10308 9 start_msgstr=start_msgstr;
10309 9 max_msgstrs=max_msgstrs;
10310
10311 9 dword section_id=ID_STRINGS;
10312 9 dword section_version=V_STRINGS;
10313 9 dword section_size = 0;
10314
10315 //section id
10316
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
10317 {
10318 new_return(1);
10319 }
10320
10321 //section version info
10322
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
10323 {
10324 new_return(2);
10325 }
10326
10327
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
10328 {
10329 new_return(3);
10330 }
10331
10332
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
10333 {
10334 18 fake_pack_writing=(writecycle==0);
10335
10336 //section size
10337
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
10338 {
10339 new_return(4);
10340 }
10341
10342 18 writesize=0;
10343
10344 //finally... section data
10345
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(msg_count,f))
10346 {
10347 return qe_invalid;
10348 }
10349
10350
2/2
✓ Branch 0 taken 836 times.
✓ Branch 1 taken 18 times.
854 for(int32_t i=0; i<msg_count; i++)
10351 {
10352 836 MsgStrings[i].ensureAsciiEncoding();
10353 836 int32_t sz = MsgStrings[i].s.size();
10354
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(sz > 8192) sz = 8192;
10355
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_iputl(sz, f))
10356 {
10357 return qe_invalid;
10358 }
10359
10360 836 char const* tmpstr = MsgStrings[i].s.c_str();
10361
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 836 times.
836 if (sz > 0)
10362 {
10363
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if (!pfwrite((void*)tmpstr,sz, f))
10364 {
10365 return qe_invalid;
10366 }
10367 836 }
10368
10369
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_iputw(MsgStrings[i].nextstring,f))
10370 {
10371 return qe_invalid;
10372 }
10373
10374
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_iputl(MsgStrings[i].tile,f))
10375 {
10376 return qe_invalid;
10377 }
10378
10379
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].cset,f))
10380 {
10381 return qe_invalid;
10382 }
10383
10384
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].trans?1:0,f))
10385 {
10386 return qe_invalid;
10387 }
10388
10389
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].font,f))
10390 {
10391 return qe_invalid;
10392 }
10393
10394
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_iputw(MsgStrings[i].x,f))
10395 {
10396 return qe_invalid;
10397 }
10398
10399
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_iputw(MsgStrings[i].y,f))
10400 {
10401 return qe_invalid;
10402 }
10403
10404
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_iputw(MsgStrings[i].w,f))
10405 {
10406 return qe_invalid;
10407 }
10408
10409
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_iputw(MsgStrings[i].h,f))
10410 {
10411 return qe_invalid;
10412 }
10413
10414
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].hspace,f))
10415 {
10416 return qe_invalid;
10417 }
10418
10419
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].vspace,f))
10420 {
10421 return qe_invalid;
10422 }
10423
10424
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].stringflags,f))
10425 {
10426 return qe_invalid;
10427 }
10428
10429
2/2
✓ Branch 0 taken 3344 times.
✓ Branch 1 taken 836 times.
4180 for(int32_t q = 0; q < 4; ++q)
10430 {
10431
1/2
✓ Branch 0 taken 3344 times.
✗ Branch 1 not taken.
3344 if(!p_putc(MsgStrings[i].margins[q],f))
10432 {
10433 return qe_invalid;
10434 }
10435 3344 }
10436
10437
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_iputl(MsgStrings[i].portrait_tile,f))
10438 {
10439 return qe_invalid;
10440 }
10441
10442
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].portrait_cset,f))
10443 {
10444 return qe_invalid;
10445 }
10446
10447
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].portrait_x,f))
10448 {
10449 return qe_invalid;
10450 }
10451
10452
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].portrait_y,f))
10453 {
10454 return qe_invalid;
10455 }
10456
10457
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].portrait_tw,f))
10458 {
10459 return qe_invalid;
10460 }
10461
10462
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].portrait_th,f))
10463 {
10464 return qe_invalid;
10465 }
10466
10467
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].shadow_type,f))
10468 {
10469 return qe_invalid;
10470 }
10471
10472
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].shadow_color,f))
10473 {
10474 return qe_invalid;
10475 }
10476
10477
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].drawlayer,f))
10478 {
10479 return qe_invalid;
10480 }
10481
10482
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].sfx,f))
10483 {
10484 return qe_invalid;
10485 }
10486
10487
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_iputw(MsgStrings[i].listpos,f))
10488 {
10489 return qe_invalid;
10490 }
10491 836 }
10492
10493
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
10494 {
10495 9 section_size=writesize;
10496 9 }
10497 18 }
10498
10499
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
10500 {
10501 char ebuf[80];
10502 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
10503 jwin_alert("Error: writestrings()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
10504 }
10505
10506 9 new_return(0);
10507 9 }
10508
10509 int32_t writestrings_text(PACKFILE *f)
10510 {
10511 std::map<int32_t, int32_t> msglistcache;
10512
10513 for(int32_t index = 1; index<msg_count; index++)
10514 {
10515 for(int32_t i=1; i<msg_count; i++)
10516 {
10517 if(MsgStrings[i].listpos==index)
10518 {
10519 msglistcache[index-1]=i;
10520 break;
10521 }
10522 }
10523 }
10524
10525 for(int32_t writecycle=0; writecycle<2; ++writecycle)
10526 {
10527 fake_pack_writing=(writecycle==0);
10528 char ebuf[32];
10529
10530 sprintf(ebuf,"Total strings: %d\n", msg_count-1);
10531
10532 if(!pfwrite(&ebuf,(int32_t)strlen(ebuf),f))
10533 {
10534 return qe_invalid;
10535 }
10536
10537 for(int32_t i=1; i<msg_count; i++)
10538 {
10539 int32_t str = msglistcache[i-1];
10540
10541 if(!str)
10542 continue;
10543
10544 if(MsgStrings[str].nextstring != 0)
10545 sprintf(ebuf,"\n\n___%d(->%d)___\n", str,MsgStrings[str].nextstring);
10546 else
10547 sprintf(ebuf,"\n\n___%d___\n", str);
10548
10549 if(!pfwrite(&ebuf,(int32_t)strlen(ebuf),f))
10550 {
10551 return qe_invalid;
10552 }
10553
10554 std::string text = MsgStrings[str].serialize();
10555 if (!pfwrite(text.c_str(), text.size(), f))
10556 {
10557 return qe_invalid;
10558 }
10559 }
10560 }
10561
10562 new_return(0);
10563 }
10564
10565 1 int32_t writestrings_tsv(PACKFILE *f)
10566 {
10567 1 std::stringstream ss;
10568
10569
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 std::vector<std::pair<std::string, std::function<std::string(const MsgStr&)>>> fields = {
10570
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "message", [&](auto& msg){ return msg.serialize(); }},
10571
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "next", [](auto& msg){ return std::to_string(msg.nextstring); } },
10572
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "tile", [](auto& msg){ return std::to_string(msg.tile); } },
10573
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "cset", [](auto& msg){ return std::to_string(msg.cset); } },
10574
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "trans", [](auto& msg){ return std::to_string(msg.trans); } },
10575
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "font", [](auto& msg){ return std::to_string(msg.font); } },
10576
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "x", [](auto& msg){ return std::to_string(msg.x); } },
10577
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "y", [](auto& msg){ return std::to_string(msg.y); } },
10578
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "w", [](auto& msg){ return std::to_string(msg.w); } },
10579
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "h", [](auto& msg){ return std::to_string(msg.h); } },
10580
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "sfx", [](auto& msg){ return std::to_string(msg.sfx); } },
10581
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "pos", [](auto& msg){ return std::to_string(msg.listpos); } },
10582
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "vspace", [](auto& msg){ return std::to_string(msg.vspace); } },
10583
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "hspace", [](auto& msg){ return std::to_string(msg.hspace); } },
10584
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "flags", [](auto& msg){ return std::to_string(msg.stringflags); } },
10585
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "margin", [](auto& msg){ return fmt::format("{} {} {} {}", msg.margins[0], msg.margins[3], msg.margins[1], msg.margins[2]); } },
10586
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "portrait_tile", [](auto& msg){ return std::to_string(msg.portrait_tile); } },
10587
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "portrait_cset", [](auto& msg){ return std::to_string(msg.portrait_cset); } },
10588
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "portrait_x", [](auto& msg){ return std::to_string(msg.portrait_x); } },
10589
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "portrait_y", [](auto& msg){ return std::to_string(msg.portrait_y); } },
10590
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "portrait_tw", [](auto& msg){ return std::to_string(msg.portrait_tw); } },
10591
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "portrait_th", [](auto& msg){ return std::to_string(msg.portrait_th); } },
10592
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "shadow_type", [](auto& msg){ return std::to_string(msg.shadow_type); } },
10593
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "shadow_color", [](auto& msg){ return std::to_string(msg.shadow_color); } },
10594
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "drawlayer", [](auto& msg){ return std::to_string(msg.drawlayer); } },
10595 };
10596
10597
1/2
✓ Branch 0 taken 25 times.
✗ Branch 1 not taken.
25 for (auto& [name, fn] : fields)
10598 {
10599
2/4
✓ Branch 0 taken 25 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 25 times.
✗ Branch 3 not taken.
50 ss << name;
10600
2/2
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 1 times.
25 if (name == fields.back().first)
10601 1 break;
10602
1/2
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
24 ss << '\t';
10603 }
10604
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 ss << '\n';
10605
10606 // First entry is a fake string, to help frame the lines. Should be helpful if manually editing these in a text editor or spreadsheet.
10607
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 ss << "|IT'S DANGEROUS TO GO || ALONE! TAKE THIS. ||LOREM IPSUM LOREM IPSU|\n";
10608
10609
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 35 times.
36 for(int32_t i=1; i<msg_count; i++)
10610 {
10611 35 auto& msg = MsgStrings[i];
10612
1/2
✓ Branch 0 taken 875 times.
✗ Branch 1 not taken.
1750 for (auto& [name, fn] : fields)
10613 {
10614
1/2
✓ Branch 0 taken 875 times.
✗ Branch 1 not taken.
875 std::string text = fn(msg);
10615
1/2
✓ Branch 0 taken 875 times.
✗ Branch 1 not taken.
875 ss << text;
10616
2/2
✓ Branch 0 taken 840 times.
✓ Branch 1 taken 35 times.
875 if (name == fields.back().first)
10617 35 break;
10618
1/2
✓ Branch 0 taken 840 times.
✗ Branch 1 not taken.
840 ss << '\t';
10619
2/3
✗ Branch 0 not taken.
✓ Branch 1 taken 35 times.
✓ Branch 2 taken 840 times.
875 }
10620
1/2
✓ Branch 0 taken 35 times.
✗ Branch 1 not taken.
35 ss << '\n';
10621 35 }
10622
10623
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 std::string text = ss.str();
10624
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 if (!pack_fwrite(text.c_str(), text.size(), f))
10625 {
10626 return qe_invalid;
10627 }
10628
10629 1 new_return(0);
10630 1 }
10631
10632 void parse_strings_tsv(std::string tsv)
10633 {
10634 std::map<std::string, std::function<void(MsgStr&, const std::string&)>> fields = {
10635 { "message", [](auto& msg, auto& text){ msg.setFromAsciiEncoding(text); } },
10636 { "next", [](auto& msg, auto& text){ msg.nextstring = std::stoi(text); } },
10637 { "tile", [](auto& msg, auto& text){ msg.tile = std::stoi(text); } },
10638 { "cset", [](auto& msg, auto& text){ msg.cset = std::stoi(text); } },
10639 { "trans", [](auto& msg, auto& text){ msg.trans = std::stoi(text); } },
10640 { "font", [](auto& msg, auto& text){ msg.font = std::stoi(text); } },
10641 { "x", [](auto& msg, auto& text){ msg.x = std::stoi(text); } },
10642 { "y", [](auto& msg, auto& text){ msg.y = std::stoi(text); } },
10643 { "w", [](auto& msg, auto& text){ msg.w = std::stoi(text); } },
10644 { "h", [](auto& msg, auto& text){ msg.h = std::stoi(text); } },
10645 { "sfx", [](auto& msg, auto& text){ msg.sfx = std::stoi(text); } },
10646 { "pos", [](auto& msg, auto& text){ msg.listpos = std::stoi(text); } },
10647 { "vspace", [](auto& msg, auto& text){ msg.vspace = std::stoi(text); } },
10648 { "hspace", [](auto& msg, auto& text){ msg.hspace = std::stoi(text); } },
10649 { "flags", [](auto& msg, auto& text){ msg.stringflags = std::stoi(text); } },
10650 { "margin", [&](auto& msg, auto& text){
10651 std::vector<std::string> strs;
10652 util::split(text, strs, ' ');
10653 if (strs.size() != 4)
10654 throw std::runtime_error("margin field must have 4 components");
10655 msg.margins[0] = std::stoi(strs[0]);
10656 msg.margins[1] = std::stoi(strs[1]);
10657 msg.margins[2] = std::stoi(strs[2]);
10658 msg.margins[3] = std::stoi(strs[3]);
10659 } },
10660 { "portrait_tile", [](auto& msg, auto& text){ msg.portrait_tile = std::stoi(text); } },
10661 { "portrait_cset", [](auto& msg, auto& text){ msg.portrait_cset = std::stoi(text); } },
10662 { "portrait_x", [](auto& msg, auto& text){ msg.portrait_x = std::stoi(text); } },
10663 { "portrait_y", [](auto& msg, auto& text){ msg.portrait_y = std::stoi(text); } },
10664 { "portrait_tw", [](auto& msg, auto& text){ msg.portrait_tw = std::stoi(text); } },
10665 { "portrait_th", [](auto& msg, auto& text){ msg.portrait_th = std::stoi(text); } },
10666 { "shadow_type", [](auto& msg, auto& text){ msg.shadow_type = std::stoi(text); } },
10667 { "shadow_color", [](auto& msg, auto& text){ msg.shadow_color = std::stoi(text); } },
10668 { "drawlayer", [](auto& msg, auto& text){ msg.drawlayer = std::stoi(text); } },
10669 };
10670
10671 std::vector<std::string> rows;
10672 util::split(tsv, rows, '\n');
10673 if (rows.size())
10674 {
10675 std::string last = rows.back();
10676 util::trimstr(last);
10677 if (last.empty())
10678 rows.pop_back();
10679 }
10680 if (rows.size() <= 1)
10681 throw std::runtime_error("missing header row");
10682
10683 std::vector<std::string> columns;
10684 util::split(rows[0], columns, '\t');
10685 for (auto name : columns)
10686 {
10687 if (!fields.contains(name))
10688 throw std::runtime_error(fmt::format("invalid field: {}", name));
10689 }
10690
10691 int start_index = 1;
10692 if (rows[start_index].find("||LOREM IPSUM") != std::string::npos)
10693 start_index += 1;
10694
10695 int num_strings = rows.size() - start_index + 1;
10696 if (num_strings > MAXMSGS-1)
10697 throw std::runtime_error(fmt::format("too many strings, max is {}", MAXMSGS-1));
10698
10699 std::vector<MsgStr> msgs;
10700 msgs.reserve(num_strings);
10701 for (int i = start_index; i < rows.size(); i++)
10702 {
10703 std::vector<std::string> strs;
10704 util::split(rows[i], strs, '\t');
10705 if (strs.size() != columns.size())
10706 throw std::runtime_error(fmt::format("row {} has {} fields, expected {}", i, strs.size(), columns.size()));
10707
10708 int j = 0;
10709 auto& msg = msgs.emplace_back();
10710 for (auto& name : columns)
10711 {
10712 auto& fn = fields[name];
10713 try
10714 {
10715 fn(msg, strs[j++]);
10716 }
10717 catch (std::exception& ex)
10718 {
10719 throw std::runtime_error(fmt::format("error parsing row {} field {}: {}", i, name, ex.what()));
10720 }
10721 }
10722 }
10723
10724 init_msgstrings(0, msgs.size());
10725 for (int i = 0; i < msgs.size(); i++)
10726 MsgStrings[i + 1] = msgs[i];
10727 msg_count = msgs.size() + 1;
10728 msglistcache.clear();
10729 }
10730
10731 bool isblanktile(tiledata *buf, int32_t i);
10732 9 int32_t writetiles(PACKFILE *f, word version, word build, int32_t start_tile, int32_t max_tiles)
10733 {
10734 //these are here to bypass compiler warnings about unused arguments
10735 9 version=version;
10736 9 build=build;
10737
10738 int32_t tiles_used;
10739 9 dword section_id=ID_TILES;
10740 9 dword section_version=V_TILES;
10741 9 al_trace("Counting tiles used\n");
10742 9 tiles_used = count_tiles(newtilebuf)-start_tile;
10743
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 tiles_used = zc_min(tiles_used, max_tiles);
10744
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 tiles_used = zc_min(tiles_used, NEWMAXTILES);
10745 9 al_trace("writetiles counted %dtiles used.\n",tiles_used);
10746 9 dword section_size = 0;
10747
10748 //section id
10749
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
10750 {
10751 new_return(1);
10752 }
10753
10754 //section version info
10755
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
10756 {
10757 new_return(2);
10758 }
10759
10760
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
10761 {
10762 new_return(3);
10763 }
10764
10765
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
10766 {
10767 18 fake_pack_writing=(writecycle==0);
10768
10769 //section size
10770
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
10771 {
10772 new_return(4);
10773 }
10774
10775 18 writesize=0;
10776
10777 //finally... section data
10778 18 tiles_used=count_tiles(newtilebuf)-start_tile;
10779
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 tiles_used=zc_min(tiles_used, max_tiles);
10780
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 tiles_used=zc_min(tiles_used, NEWMAXTILES);
10781
10782
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(tiles_used,f))
10783 {
10784 new_return(5);
10785 }
10786
10787
2/2
✓ Branch 0 taken 696384 times.
✓ Branch 1 taken 18 times.
696402 for(int32_t i=0; i<tiles_used; ++i)
10788 {
10789
2/2
✓ Branch 0 taken 365770 times.
✓ Branch 1 taken 330614 times.
696384 if(isblanktile(newtilebuf, start_tile+i))
10790 {
10791
1/2
✓ Branch 0 taken 365770 times.
✗ Branch 1 not taken.
365770 if(!p_putc(0,f))
10792 new_return(8);
10793 365770 }
10794 else
10795 {
10796 330614 int format = newtilebuf[start_tile+i].format;
10797
1/2
✓ Branch 0 taken 330614 times.
✗ Branch 1 not taken.
330614 if(!p_putc(format,f))
10798 {
10799 new_return(6);
10800 }
10801
10802
2/2
✓ Branch 0 taken 327742 times.
✓ Branch 1 taken 2872 times.
330614 if (format == tf4Bit)
10803 {
10804 byte temp_tile[128];
10805 327742 byte *di = temp_tile;
10806 327742 byte *src = newtilebuf[start_tile+i].data;
10807
2/2
✓ Branch 0 taken 41950976 times.
✓ Branch 1 taken 327742 times.
42278718 for (int32_t si=0; si<256; si+=2)
10808 {
10809 41950976 *di = (src[si]&15) + ((src[si+1]&15) << 4);
10810 41950976 ++di;
10811 41950976 }
10812
1/2
✓ Branch 0 taken 327742 times.
✗ Branch 1 not taken.
327742 if (!pfwrite(temp_tile,128,f))
10813 {
10814 new_return(7);
10815 }
10816 327742 }
10817
1/2
✓ Branch 0 taken 2872 times.
✗ Branch 1 not taken.
2872 else if (!pfwrite(newtilebuf[start_tile+i].data,tilesize(format),f))
10818 {
10819 new_return(7);
10820 }
10821 }
10822 696384 }
10823
10824
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
10825 {
10826 9 section_size=writesize;
10827 9 }
10828 18 }
10829
10830
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
10831 {
10832 char ebuf[80];
10833 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
10834 jwin_alert("Error: writetiles()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
10835 }
10836
10837 9 new_return(0);
10838 }
10839
10840 /* MIDI Format
10841 section_id LONG
10842 section_version WORD
10843 section_cversion WORD
10844 section_size LONG
10845 midi_flags 32 Byte ? BITFIELD[252]
10846
10847 [
10848 title 36
10849 start 4
10850 loop_start 4
10851 loop_end 4
10852 loop 2
10853 volume 2
10854 midi *
10855 ]
10856
10857 */
10858
10859 9 int32_t writemidis(PACKFILE *f)
10860 {
10861 9 dword section_id=ID_MIDIS;
10862 9 dword section_version=V_MIDIS;
10863 9 dword section_size = 0;
10864
10865 //section id
10866
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
10867 {
10868 new_return(1);
10869 }
10870
10871 //section version info
10872
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
10873 {
10874 new_return(2);
10875 }
10876
10877
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
10878 {
10879 new_return(3);
10880 }
10881
10882
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 18 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
10883 {
10884 18 fake_pack_writing=(writecycle==0);
10885
10886 //section size
10887
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
10888 {
10889 new_return(4);
10890 }
10891
10892 18 writesize=0;
10893
10894 //finally... section data
10895
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(midi_flags,sizeof(midi_flags),f))
10896 {
10897 new_return(5);
10898 }
10899
10900
2/2
✓ Branch 0 taken 4536 times.
✓ Branch 1 taken 18 times.
4554 for(int32_t i=0; i<MAXCUSTOMMIDIS; i++)
10901 {
10902
2/2
✓ Branch 0 taken 4406 times.
✓ Branch 1 taken 130 times.
4536 if(get_bit(midi_flags,i))
10903 {
10904
1/2
✓ Branch 0 taken 130 times.
✗ Branch 1 not taken.
130 if(!pfwrite(&customtunes[i].title,sizeof(customtunes[0].title)-1,f))
10905 {
10906 new_return(6);
10907 }
10908
10909
1/2
✓ Branch 0 taken 130 times.
✗ Branch 1 not taken.
130 if(!p_iputl(customtunes[i].start,f))
10910 {
10911 new_return(7);
10912 }
10913
10914
1/2
✓ Branch 0 taken 130 times.
✗ Branch 1 not taken.
130 if(!p_iputl(customtunes[i].loop_start,f))
10915 {
10916 new_return(8);
10917 }
10918
10919
1/2
✓ Branch 0 taken 130 times.
✗ Branch 1 not taken.
130 if(!p_iputl(customtunes[i].loop_end,f))
10920 {
10921 new_return(9);
10922 }
10923
10924
1/2
✓ Branch 0 taken 130 times.
✗ Branch 1 not taken.
130 if(!p_iputw(customtunes[i].loop,f))
10925 {
10926 new_return(10);
10927 }
10928
10929
1/2
✓ Branch 0 taken 130 times.
✗ Branch 1 not taken.
130 if(!p_iputw(customtunes[i].volume,f))
10930 {
10931 new_return(11);
10932 }
10933
10934
1/2
✓ Branch 0 taken 130 times.
✗ Branch 1 not taken.
130 if(!pfwrite(&customtunes[i].flags, sizeof(customtunes[i].flags),f))
10935 {
10936 new_return(12);
10937 }
10938
10939 130 byte format = MFORMAT_MIDI;
10940
1/2
✓ Branch 0 taken 130 times.
✗ Branch 1 not taken.
130 if(!pfwrite(&format, sizeof(format),f))
10941 {
10942 new_return(13);
10943 }
10944
10945
1/2
✓ Branch 0 taken 130 times.
✗ Branch 1 not taken.
130 if (!write_midi(customtunes[i].data, f)) new_return(14);
10946 130 }
10947 4536 }
10948
10949
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
10950 {
10951 9 section_size=writesize;
10952 9 }
10953 18 }
10954
10955
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
10956 {
10957 char ebuf[80];
10958 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
10959 jwin_alert("Error: writemidis()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
10960 }
10961
10962 9 new_return(0);
10963 }
10964
10965 9 int32_t writecheats(PACKFILE *f, zquestheader *Header)
10966 {
10967 9 dword section_id=ID_CHEATS;
10968 9 dword section_version=V_CHEATS;
10969 9 dword section_size = 0;
10970
10971 //section id
10972
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
10973 {
10974 new_return(1);
10975 }
10976
10977 //section version info
10978
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
10979 {
10980 new_return(2);
10981 }
10982
10983
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
10984 {
10985 new_return(3);
10986 }
10987
10988
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 18 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
10989 {
10990 18 fake_pack_writing=(writecycle==0);
10991
10992 //section size
10993
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
10994 {
10995 new_return(4);
10996 }
10997
10998 18 writesize=0;
10999
11000 //finally... section data
11001
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(Header->data_flags[ZQ_CHEATS2],f))
11002 {
11003 new_return(5);
11004 }
11005
11006
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 if(Header->data_flags[ZQ_CHEATS2])
11007 {
11008
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(zcheats.flags,f))
11009 {
11010 new_return(6);
11011 }
11012
11013
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(&zcheats.codes, sizeof(zcheats.codes), f))
11014 {
11015 new_return(7);
11016 }
11017 18 }
11018
11019
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
11020 {
11021 9 section_size=writesize;
11022 9 }
11023 18 }
11024
11025
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
11026 {
11027 char ebuf[80];
11028 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
11029 jwin_alert("Error: writecheats()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
11030 }
11031
11032 9 new_return(0);
11033 }
11034
11035 9 int32_t writeguys(PACKFILE *f, zquestheader *Header)
11036 {
11037 //these are here to bypass compiler warnings about unused arguments
11038 9 Header=Header;
11039
11040 9 dword section_id=ID_GUYS;
11041 9 dword section_version=V_GUYS;
11042 9 dword section_size=0;
11043
11044 //section id
11045
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
11046 {
11047 new_return(1);
11048 }
11049
11050 //section version info
11051
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
11052 {
11053 new_return(2);
11054 }
11055
11056
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
11057 {
11058 new_return(3);
11059 }
11060
11061
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
11062 {
11063 18 fake_pack_writing=(writecycle==0);
11064
11065 //section size
11066
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
11067 {
11068 new_return(4);
11069 }
11070
11071 18 writesize=0;
11072
11073 //finally... section data
11074
2/2
✓ Branch 0 taken 9216 times.
✓ Branch 1 taken 18 times.
9234 for(int32_t i=0; i<MAXGUYS; i++)
11075 {
11076
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!pfwrite((char *)guy_string[i], 64, f))
11077 {
11078 new_return(5);
11079 }
11080 9216 }
11081
11082
2/2
✓ Branch 0 taken 9216 times.
✓ Branch 1 taken 18 times.
9234 for(int32_t i=0; i<MAXGUYS; i++)
11083 {
11084 9216 uint32_t flags1 = uint32_t(guysbuf[i].flags);
11085 9216 uint32_t flags2 = uint32_t(guysbuf[i].flags >> 32ULL);
11086
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if (!p_iputl(flags1, f))
11087 {
11088 new_return(6);
11089 }
11090
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if (!p_iputl(flags2, f))
11091 {
11092 new_return(7);
11093 }
11094
11095
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].tile,f))
11096 {
11097 new_return(8);
11098 }
11099
11100
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(guysbuf[i].width,f))
11101 {
11102 new_return(9);
11103 }
11104
11105
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(guysbuf[i].height,f))
11106 {
11107 new_return(10);
11108 }
11109
11110
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].s_tile,f))
11111 {
11112 new_return(11);
11113 }
11114
11115
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(guysbuf[i].s_width,f))
11116 {
11117 new_return(12);
11118 }
11119
11120
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(guysbuf[i].s_height,f))
11121 {
11122 new_return(13);
11123 }
11124
11125
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].e_tile,f))
11126 {
11127 new_return(14);
11128 }
11129
11130
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(guysbuf[i].e_width,f))
11131 {
11132 new_return(15);
11133 }
11134
11135
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(guysbuf[i].e_height,f))
11136 {
11137 new_return(16);
11138 }
11139
11140
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].hp,f))
11141 {
11142 new_return(17);
11143 }
11144
11145
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].type,f))
11146 {
11147 new_return(18);
11148 }
11149
11150
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].cset,f))
11151 {
11152 new_return(19);
11153 }
11154
11155
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].anim,f))
11156 {
11157 new_return(20);
11158 }
11159
11160
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].e_anim,f))
11161 {
11162 new_return(21);
11163 }
11164
11165
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].frate,f))
11166 {
11167 new_return(22);
11168 }
11169
11170
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].e_frate,f))
11171 {
11172 new_return(23);
11173 }
11174
11175
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].dp,f))
11176 {
11177 new_return(24);
11178 }
11179
11180
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].wdp,f))
11181 {
11182 new_return(25);
11183 }
11184
11185
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].weapon,f))
11186 {
11187 new_return(26);
11188 }
11189
11190
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].rate,f))
11191 {
11192 new_return(27);
11193 }
11194
11195
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].hrate,f))
11196 {
11197 new_return(28);
11198 }
11199
11200
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].step,f))
11201 {
11202 new_return(29);
11203 }
11204
11205
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].homing,f))
11206 {
11207 new_return(30);
11208 }
11209
11210
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].grumble,f))
11211 {
11212 new_return(31);
11213 }
11214
11215
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].item_set,f))
11216 {
11217 new_return(32);
11218 }
11219
11220
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[0], f))
11221 {
11222 new_return(33);
11223 }
11224
11225
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[1],f))
11226 {
11227 new_return(34);
11228 }
11229
11230
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[2],f))
11231 {
11232 new_return(35);
11233 }
11234
11235
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[3],f))
11236 {
11237 new_return(36);
11238 }
11239
11240
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[4],f))
11241 {
11242 new_return(37);
11243 }
11244
11245
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[5],f))
11246 {
11247 new_return(38);
11248 }
11249
11250
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[6],f))
11251 {
11252 new_return(39);
11253 }
11254
11255
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[7],f))
11256 {
11257 new_return(40);
11258 }
11259
11260
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[8],f))
11261 {
11262 new_return(41);
11263 }
11264
11265
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[9],f))
11266 {
11267 new_return(42);
11268 }
11269
11270
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].bgsfx,f))
11271 {
11272 new_return(43);
11273 }
11274
11275
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].bosspal,f))
11276 {
11277 new_return(44);
11278 }
11279
11280
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].extend,f))
11281 {
11282 new_return(45);
11283 }
11284
11285
2/2
✓ Branch 0 taken 175104 times.
✓ Branch 1 taken 9216 times.
184320 for(int32_t j=0; j < edefLAST; j++)
11286 {
11287
1/2
✓ Branch 0 taken 175104 times.
✗ Branch 1 not taken.
175104 if(!p_putc(guysbuf[i].defense[j],f))
11288 {
11289 new_return(46);
11290 }
11291 175104 }
11292
11293
5/6
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6144 times.
✓ Branch 3 taken 3072 times.
✓ Branch 4 taken 2048 times.
✓ Branch 5 taken 4096 times.
9216 if ( FFCore.getQuestHeaderInfo(vZelda) < 0x250 || (( FFCore.getQuestHeaderInfo(vZelda) == 0x250 ) && FFCore.getQuestHeaderInfo(vBuild) < 32 ) )
11294 {
11295 //If no user-set hit sound was in place, and the quest was made in a version before 2.53.0 Gamma 2:
11296
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2048 times.
2048 if ( guysbuf[i].hitsfx == 0 ) guysbuf[i].hitsfx = WAV_EHIT; //Fix quests using the wrong hit sound when loading this.
11297 //Force SFX_HIT here.
11298
11299 2048 }
11300
11301
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(guysbuf[i].hitsfx,f))
11302 {
11303 new_return(47);
11304 }
11305
11306
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(guysbuf[i].deadsfx,f))
11307 {
11308 new_return(48);
11309 }
11310
11311
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[10],f))
11312 {
11313 new_return(49);
11314 }
11315
11316
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[11],f))
11317 {
11318 new_return(50);
11319 }
11320
11321 //New 2.6 defences
11322
2/2
✓ Branch 0 taken 202752 times.
✓ Branch 1 taken 9216 times.
211968 for(int32_t j=edefLAST; j < edefLAST255; j++)
11323 {
11324
1/2
✓ Branch 0 taken 202752 times.
✗ Branch 1 not taken.
202752 if(!p_putc(guysbuf[i].defense[j],f))
11325 {
11326 new_return(51);
11327 }
11328 202752 }
11329
11330 //tilewidth, tileheight, hitwidth, hitheight, hitzheight, hitxofs, hityofs, hitzofs
11331
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].txsz,f))
11332 {
11333 new_return(52);
11334 }
11335
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].tysz,f))
11336 {
11337 new_return(53);
11338 }
11339
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].hxsz,f))
11340 {
11341 new_return(54);
11342 }
11343
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].hysz,f))
11344 {
11345 new_return(55);
11346 }
11347
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].hzsz,f))
11348 {
11349 new_return(56);
11350 }
11351 // These are not fixed types, but ints, so they are safe to use here.
11352
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].hxofs,f))
11353 {
11354 new_return(57);
11355 }
11356
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].hyofs,f))
11357 {
11358 new_return(58);
11359 }
11360
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].xofs,f))
11361 {
11362 new_return(59);
11363 }
11364
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].yofs,f))
11365 {
11366 new_return(60);
11367 }
11368
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].zofs,f))
11369 {
11370 new_return(61);
11371 }
11372
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].wpnsprite,f))
11373 {
11374 new_return(62);
11375 }
11376
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].SIZEflags,f))
11377 {
11378 new_return(63);
11379 }
11380
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].frozentile,f))
11381 {
11382 new_return(64);
11383 }
11384
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].frozencset,f))
11385 {
11386 new_return(65);
11387 }
11388
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].frozenclock,f))
11389 {
11390 new_return(66);
11391 }
11392
11393
2/2
✓ Branch 0 taken 92160 times.
✓ Branch 1 taken 9216 times.
101376 for ( int32_t q = 0; q < 10; q++ )
11394 {
11395
1/2
✓ Branch 0 taken 92160 times.
✗ Branch 1 not taken.
92160 if(!p_iputw(guysbuf[i].frozenmisc[q],f))
11396 {
11397 new_return(67);
11398 }
11399 92160 }
11400
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].firesfx,f))
11401 {
11402 new_return(68);
11403 }
11404 //misc 16->31
11405
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[15],f))
11406 {
11407 new_return(69);
11408 }
11409
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[16],f))
11410 {
11411 new_return(70);
11412 }
11413
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[17],f))
11414 {
11415 new_return(71);
11416 }
11417
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[18],f))
11418 {
11419 new_return(72);
11420 }
11421
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[19],f))
11422 {
11423 new_return(73);
11424 }
11425
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[20],f))
11426 {
11427 new_return(74);
11428 }
11429
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[21],f))
11430 {
11431 new_return(75);
11432 }
11433
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[22],f))
11434 {
11435 new_return(76);
11436 }
11437
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[23],f))
11438 {
11439 new_return(77);
11440 }
11441
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[24],f))
11442 {
11443 new_return(78);
11444 }
11445
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[25],f))
11446 {
11447 new_return(79);
11448 }
11449
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[26],f))
11450 {
11451 new_return(80);
11452 }
11453
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[27],f))
11454 {
11455 new_return(81);
11456 }
11457
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[28],f))
11458 {
11459 new_return(82);
11460 }
11461
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[29],f))
11462 {
11463 new_return(83);
11464 }
11465
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[30],f))
11466 {
11467 new_return(84);
11468 }
11469
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[31],f))
11470 {
11471 new_return(85);
11472 }
11473
2/2
✓ Branch 0 taken 294912 times.
✓ Branch 1 taken 9216 times.
304128 for ( int32_t q = 0; q < 32; q++ )
11474 {
11475
1/2
✓ Branch 0 taken 294912 times.
✗ Branch 1 not taken.
294912 if(!p_iputl(guysbuf[i].movement[q],f))
11476 {
11477 new_return(86);
11478 }
11479 294912 }
11480
2/2
✓ Branch 0 taken 294912 times.
✓ Branch 1 taken 9216 times.
304128 for ( int32_t q = 0; q < 32; q++ )
11481 {
11482
1/2
✓ Branch 0 taken 294912 times.
✗ Branch 1 not taken.
294912 if(!p_iputl(guysbuf[i].new_weapon[q],f))
11483 {
11484 new_return(87);
11485 }
11486 294912 }
11487
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].script,f))
11488 {
11489 new_return(88);
11490 }
11491
2/2
✓ Branch 0 taken 73728 times.
✓ Branch 1 taken 9216 times.
82944 for ( int32_t q = 0; q < 8; q++ )
11492 {
11493
1/2
✓ Branch 0 taken 73728 times.
✗ Branch 1 not taken.
73728 if(!p_iputl(guysbuf[i].initD[q],f))
11494 {
11495 new_return(89);
11496 }
11497 73728 }
11498
2/2
✓ Branch 0 taken 18432 times.
✓ Branch 1 taken 9216 times.
27648 for ( int32_t q = 0; q < 2; q++ )
11499 {
11500
1/2
✓ Branch 0 taken 18432 times.
✗ Branch 1 not taken.
18432 if(!p_iputl(0,f))
11501 {
11502 new_return(90);
11503 }
11504 18432 }
11505
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].editorflags,f))
11506 {
11507 new_return(91);
11508 }
11509 //somehow forgot these in the older builds -Z
11510
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[12],f))
11511 {
11512 new_return(92);
11513 }
11514
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[13],f))
11515 {
11516 new_return(93);
11517 }
11518
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[14],f))
11519 {
11520 new_return(94);
11521 }
11522
11523 //Enemy Editor InitD[] labels
11524
2/2
✓ Branch 0 taken 73728 times.
✓ Branch 1 taken 9216 times.
82944 for ( int32_t q = 0; q < 8; q++ )
11525 {
11526
2/2
✓ Branch 0 taken 73728 times.
✓ Branch 1 taken 4792320 times.
4866048 for ( int32_t w = 0; w < 65; w++ )
11527 {
11528
1/2
✓ Branch 0 taken 4792320 times.
✗ Branch 1 not taken.
4792320 if(!p_putc(guysbuf[i].initD_label[q][w],f))
11529 {
11530 new_return(95);
11531 }
11532 4792320 }
11533 73728 }
11534
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].moveflags,f))
11535 new_return(99);
11536
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(guysbuf[i].spr_shadow,f))
11537 new_return(100);
11538
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(guysbuf[i].spr_death,f))
11539 new_return(101);
11540
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(guysbuf[i].spr_spawn,f))
11541 new_return(102);
11542
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if (!p_putc(guysbuf[i].specialsfx, f))
11543 new_return(103);
11544
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9216 times.
9216 if(auto ret = write_weap_data(guysbuf[i].weap_data, f))
11545 return ret;
11546 9216 }
11547
11548
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
11549 {
11550 9 section_size=writesize;
11551 9 }
11552 18 }
11553
11554
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
11555 {
11556 char ebuf[80];
11557 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
11558 jwin_alert("Error: writeguys()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
11559 }
11560
11561 9 new_return(0);
11562 9 }
11563
11564 9 int32_t writeherosprites(PACKFILE *f, zquestheader *Header)
11565 {
11566 //these are here to bypass compiler warnings about unused arguments
11567 9 Header=Header;
11568
11569 9 dword section_id=ID_HEROSPRITES;
11570 9 dword section_version=V_HEROSPRITES;
11571 9 dword section_size=0;
11572
11573 //section id
11574
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
11575 {
11576 new_return(1);
11577 }
11578
11579 //section version info
11580
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
11581 {
11582 new_return(2);
11583 }
11584
11585
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
11586 {
11587 new_return(3);
11588 }
11589
11590
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 18 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
11591 {
11592 18 fake_pack_writing=(writecycle==0);
11593
11594 //section size
11595
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
11596 {
11597 new_return(4);
11598 }
11599
11600 18 writesize=0;
11601
11602 //finally... section data
11603
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t i=0; i<4; i++)
11604 {
11605
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(walkspr[i][spr_tile],f))
11606 {
11607 new_return(5);
11608 }
11609
11610
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)walkspr[i][spr_flip],f))
11611 {
11612 new_return(5);
11613 }
11614
11615
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)walkspr[i][spr_extend],f))
11616 {
11617 new_return(5);
11618 }
11619 72 }
11620
11621
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t i=0; i<4; i++)
11622 {
11623
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(stabspr[i][spr_tile],f))
11624 {
11625 new_return(6);
11626 }
11627
11628
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)stabspr[i][spr_flip],f))
11629 {
11630 new_return(6);
11631 }
11632
11633
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)stabspr[i][spr_extend],f))
11634 {
11635 new_return(6);
11636 }
11637 72 }
11638
11639
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t i=0; i<4; i++)
11640 {
11641
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(slashspr[i][spr_tile],f))
11642 {
11643 new_return(7);
11644 }
11645
11646
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)slashspr[i][spr_flip],f))
11647 {
11648 new_return(7);
11649 }
11650
11651
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)slashspr[i][spr_extend],f))
11652 {
11653 new_return(7);
11654 }
11655 72 }
11656
11657
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t i=0; i<4; i++)
11658 {
11659
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(floatspr[i][spr_tile],f))
11660 {
11661 new_return(8);
11662 }
11663
11664
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)floatspr[i][spr_flip],f))
11665 {
11666 new_return(8);
11667 }
11668
11669
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)floatspr[i][spr_extend],f))
11670 {
11671 new_return(8);
11672 }
11673 72 }
11674
11675
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t i=0; i<4; i++)
11676 {
11677
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(swimspr[i][spr_tile],f))
11678 {
11679 new_return(8);
11680 }
11681
11682
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)swimspr[i][spr_flip],f))
11683 {
11684 new_return(8);
11685 }
11686
11687
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)swimspr[i][spr_extend],f))
11688 {
11689 new_return(8);
11690 }
11691 72 }
11692
11693
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t i=0; i<4; i++)
11694 {
11695
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(divespr[i][spr_tile],f))
11696 {
11697 new_return(9);
11698 }
11699
11700
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)divespr[i][spr_flip],f))
11701 {
11702 new_return(9);
11703 }
11704
11705
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)divespr[i][spr_extend],f))
11706 {
11707 new_return(9);
11708 }
11709 72 }
11710
11711
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t i=0; i<4; i++)
11712 {
11713
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(poundspr[i][spr_tile],f))
11714 {
11715 new_return(10);
11716 }
11717
11718
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)poundspr[i][spr_flip],f))
11719 {
11720 new_return(10);
11721 }
11722
11723
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)poundspr[i][spr_extend],f))
11724 {
11725 new_return(10);
11726 }
11727 72 }
11728
11729
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(castingspr[spr_tile],f))
11730 {
11731 new_return(11);
11732 }
11733
11734
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc((byte)castingspr[spr_flip],f))
11735 {
11736 new_return(11);
11737 }
11738
11739
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc((byte)castingspr[spr_extend],f))
11740 {
11741 new_return(11);
11742 }
11743
11744
2/2
✓ Branch 0 taken 36 times.
✓ Branch 1 taken 18 times.
54 for(int32_t i=0; i<2; i++)
11745 {
11746
2/2
✓ Branch 0 taken 108 times.
✓ Branch 1 taken 36 times.
144 for(int32_t j=0; j<spr_holdmax; j++)
11747 {
11748
1/2
✓ Branch 0 taken 108 times.
✗ Branch 1 not taken.
108 if(!p_iputl(holdspr[i][j][spr_tile],f))
11749 {
11750 new_return(12);
11751 }
11752
11753
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 108 times.
108 if(!p_putc((byte)holdspr[i][j][spr_flip],f))
11754 {
11755 new_return(12);
11756 }
11757
11758
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 108 times.
108 if(!p_putc((byte)holdspr[i][j][spr_extend],f))
11759 {
11760 new_return(12);
11761 }
11762 108 }
11763 36 }
11764
11765
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t i=0; i<4; i++)
11766 {
11767
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(jumpspr[i][spr_tile],f))
11768 {
11769 new_return(13);
11770 }
11771
11772
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)jumpspr[i][spr_flip],f))
11773 {
11774 new_return(13);
11775 }
11776
11777
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)jumpspr[i][spr_extend],f))
11778 {
11779 new_return(13);
11780 }
11781 72 }
11782
11783
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t i=0; i<4; i++)
11784 {
11785
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(chargespr[i][spr_tile],f))
11786 {
11787 new_return(13);
11788 }
11789
11790
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)chargespr[i][spr_flip],f))
11791 {
11792 new_return(13);
11793 }
11794
11795
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)chargespr[i][spr_extend],f))
11796 {
11797 new_return(13);
11798 }
11799 72 }
11800
11801
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc((byte)zinit.hero_swim_speed,f))
11802 {
11803 new_return(14);
11804 }
11805
11806 //{ V_HEROSPRITES >= 7
11807
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11808 {
11809
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(frozenspr[q][spr_tile],f))
11810 new_return(15);
11811
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)frozenspr[q][spr_flip],f))
11812 new_return(15);
11813
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)frozenspr[q][spr_extend],f))
11814 new_return(15);
11815 72 }
11816
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11817 {
11818
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(frozen_waterspr[q][spr_tile],f))
11819 new_return(15);
11820
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)frozen_waterspr[q][spr_flip],f))
11821 new_return(15);
11822
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)frozen_waterspr[q][spr_extend],f))
11823 new_return(15);
11824 72 }
11825
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11826 {
11827
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(onfirespr[q][spr_tile],f))
11828 new_return(15);
11829
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)onfirespr[q][spr_flip],f))
11830 new_return(15);
11831
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)onfirespr[q][spr_extend],f))
11832 new_return(15);
11833 72 }
11834
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11835 {
11836
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(onfire_waterspr[q][spr_tile],f))
11837 new_return(15);
11838
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)onfire_waterspr[q][spr_flip],f))
11839 new_return(15);
11840
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)onfire_waterspr[q][spr_extend],f))
11841 new_return(15);
11842 72 }
11843
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11844 {
11845
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(diggingspr[q][spr_tile],f))
11846 new_return(15);
11847
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)diggingspr[q][spr_flip],f))
11848 new_return(15);
11849
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)diggingspr[q][spr_extend],f))
11850 new_return(15);
11851 72 }
11852
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11853 {
11854
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(usingrodspr[q][spr_tile],f))
11855 new_return(15);
11856
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)usingrodspr[q][spr_flip],f))
11857 new_return(15);
11858
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)usingrodspr[q][spr_extend],f))
11859 new_return(15);
11860 72 }
11861
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11862 {
11863
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(usingcanespr[q][spr_tile],f))
11864 new_return(15);
11865
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)usingcanespr[q][spr_flip],f))
11866 new_return(15);
11867
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)usingcanespr[q][spr_extend],f))
11868 new_return(15);
11869 72 }
11870
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11871 {
11872
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(pushingspr[q][spr_tile],f))
11873 new_return(15);
11874
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)pushingspr[q][spr_flip],f))
11875 new_return(15);
11876
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)pushingspr[q][spr_extend],f))
11877 new_return(15);
11878 72 }
11879
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11880 {
11881
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(liftingspr[q][spr_tile],f))
11882 new_return(15);
11883
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)liftingspr[q][spr_flip],f))
11884 new_return(15);
11885
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)liftingspr[q][spr_extend],f))
11886 new_return(15);
11887
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)liftingspr[q][spr_frames],f))
11888 new_return(15);
11889 72 }
11890
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11891 {
11892
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(liftingwalkspr[q][spr_tile],f))
11893 new_return(15);
11894
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)liftingwalkspr[q][spr_flip],f))
11895 new_return(15);
11896
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)liftingwalkspr[q][spr_extend],f))
11897 new_return(15);
11898 72 }
11899
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11900 {
11901
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(stunnedspr[q][spr_tile],f))
11902 new_return(15);
11903
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)stunnedspr[q][spr_flip],f))
11904 new_return(15);
11905
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)stunnedspr[q][spr_extend],f))
11906 new_return(15);
11907 72 }
11908
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11909 {
11910
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(stunned_waterspr[q][spr_tile],f))
11911 new_return(15);
11912
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)stunned_waterspr[q][spr_flip],f))
11913 new_return(15);
11914
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)stunned_waterspr[q][spr_extend],f))
11915 new_return(15);
11916 72 }
11917
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11918 {
11919
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(drowningspr[q][spr_tile],f))
11920 new_return(15);
11921
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)drowningspr[q][spr_flip],f))
11922 new_return(15);
11923
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)drowningspr[q][spr_extend],f))
11924 new_return(15);
11925 72 }
11926
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11927 {
11928
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(drowning_lavaspr[q][spr_tile],f))
11929 new_return(15);
11930
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)drowning_lavaspr[q][spr_flip],f))
11931 new_return(15);
11932
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)drowning_lavaspr[q][spr_extend],f))
11933 new_return(15);
11934 72 }
11935
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11936 {
11937
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(fallingspr[q][spr_tile],f))
11938 new_return(15);
11939
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)fallingspr[q][spr_flip],f))
11940 new_return(15);
11941
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)fallingspr[q][spr_extend],f))
11942 new_return(15);
11943 72 }
11944
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11945 {
11946
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(shockedspr[q][spr_tile],f))
11947 new_return(15);
11948
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)shockedspr[q][spr_flip],f))
11949 new_return(15);
11950
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)shockedspr[q][spr_extend],f))
11951 new_return(15);
11952 72 }
11953
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11954 {
11955
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(shocked_waterspr[q][spr_tile],f))
11956 new_return(15);
11957
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)shocked_waterspr[q][spr_flip],f))
11958 new_return(15);
11959
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)shocked_waterspr[q][spr_extend],f))
11960 new_return(15);
11961 72 }
11962
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11963 {
11964
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(pullswordspr[q][spr_tile],f))
11965 new_return(15);
11966
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)pullswordspr[q][spr_flip],f))
11967 new_return(15);
11968
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)pullswordspr[q][spr_extend],f))
11969 new_return(15);
11970 72 }
11971
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11972 {
11973
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(readingspr[q][spr_tile],f))
11974 new_return(15);
11975
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)readingspr[q][spr_flip],f))
11976 new_return(15);
11977
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)readingspr[q][spr_extend],f))
11978 new_return(15);
11979 72 }
11980
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11981 {
11982
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(slash180spr[q][spr_tile],f))
11983 new_return(15);
11984
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)slash180spr[q][spr_flip],f))
11985 new_return(15);
11986
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)slash180spr[q][spr_extend],f))
11987 new_return(15);
11988 72 }
11989
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11990 {
11991
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(slashZ4spr[q][spr_tile],f))
11992 new_return(15);
11993
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)slashZ4spr[q][spr_flip],f))
11994 new_return(15);
11995
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)slashZ4spr[q][spr_extend],f))
11996 new_return(15);
11997 72 }
11998
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11999 {
12000
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(dashspr[q][spr_tile],f))
12001 new_return(15);
12002
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)dashspr[q][spr_flip],f))
12003 new_return(15);
12004
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)dashspr[q][spr_extend],f))
12005 new_return(15);
12006 72 }
12007
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
12008 {
12009
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(bonkspr[q][spr_tile],f))
12010 new_return(15);
12011
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)bonkspr[q][spr_flip],f))
12012 new_return(15);
12013
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)bonkspr[q][spr_extend],f))
12014 new_return(15);
12015 72 }
12016
2/2
✓ Branch 0 taken 54 times.
✓ Branch 1 taken 18 times.
72 for(int32_t q = 0; q < 3; ++q) //Not directions; number of medallion sprs
12017 {
12018
1/2
✓ Branch 0 taken 54 times.
✗ Branch 1 not taken.
54 if(!p_iputl(medallionsprs[q][spr_tile],f))
12019 new_return(15);
12020
1/2
✓ Branch 0 taken 54 times.
✗ Branch 1 not taken.
54 if(!p_putc((byte)medallionsprs[q][spr_flip],f))
12021 new_return(15);
12022
1/2
✓ Branch 0 taken 54 times.
✗ Branch 1 not taken.
54 if(!p_putc((byte)medallionsprs[q][spr_extend],f))
12023 new_return(15);
12024 54 }
12025
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
12026 {
12027
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(sideswimspr[q][spr_tile],f))
12028 new_return(16);
12029
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)sideswimspr[q][spr_flip],f))
12030 new_return(16);
12031
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)sideswimspr[q][spr_extend],f))
12032 new_return(16);
12033 72 }
12034
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
12035 {
12036
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(sideswimslashspr[q][spr_tile],f))
12037 new_return(17);
12038
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)sideswimslashspr[q][spr_flip],f))
12039 new_return(17);
12040
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)sideswimslashspr[q][spr_extend],f))
12041 new_return(17);
12042 72 }
12043
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
12044 {
12045
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(sideswimstabspr[q][spr_tile],f))
12046 new_return(17);
12047
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)sideswimstabspr[q][spr_flip],f))
12048 new_return(17);
12049
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)sideswimstabspr[q][spr_extend],f))
12050 new_return(17);
12051 72 }
12052
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
12053 {
12054
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(sideswimpoundspr[q][spr_tile],f))
12055 new_return(17);
12056
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)sideswimpoundspr[q][spr_flip],f))
12057 new_return(17);
12058
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)sideswimpoundspr[q][spr_extend],f))
12059 new_return(17);
12060 72 }
12061
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
12062 {
12063
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(sideswimchargespr[q][spr_tile],f))
12064 new_return(18);
12065
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)sideswimchargespr[q][spr_flip],f))
12066 new_return(18);
12067
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)sideswimchargespr[q][spr_extend],f))
12068 new_return(18);
12069 72 }
12070
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
12071 {
12072
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(hammeroffsets[q],f))
12073 new_return(19);
12074 72 }
12075
2/2
✓ Branch 0 taken 54 times.
✓ Branch 1 taken 18 times.
72 for(int32_t q = 0; q < 3; ++q)
12076 {
12077
1/2
✓ Branch 0 taken 54 times.
✗ Branch 1 not taken.
54 if(!p_iputl(sideswimholdspr[q][spr_tile],f))
12078 new_return(20);
12079
1/2
✓ Branch 0 taken 54 times.
✗ Branch 1 not taken.
54 if(!p_putc((byte)sideswimholdspr[q][spr_flip],f))
12080 new_return(20);
12081
1/2
✓ Branch 0 taken 54 times.
✗ Branch 1 not taken.
54 if(!p_putc((byte)sideswimholdspr[q][spr_extend],f))
12082 new_return(20);
12083 54 }
12084
12085
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(sideswimcastingspr[spr_tile],f))
12086 {
12087 new_return(21);
12088 }
12089
12090
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc((byte)sideswimcastingspr[spr_flip],f))
12091 {
12092 new_return(21);
12093 }
12094
12095
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc((byte)sideswimcastingspr[spr_extend],f))
12096 {
12097 new_return(21);
12098 }
12099
12100
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
12101 {
12102
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(sidedrowningspr[q][spr_tile],f))
12103 new_return(22);
12104
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)sidedrowningspr[q][spr_flip],f))
12105 new_return(22);
12106
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)sidedrowningspr[q][spr_extend],f))
12107 new_return(22);
12108 72 }
12109
12110
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t i=0; i<4; i++)
12111 {
12112
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(revslashspr[i][spr_tile],f))
12113 {
12114 new_return(23);
12115 }
12116
12117
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)revslashspr[i][spr_flip],f))
12118 {
12119 new_return(23);
12120 }
12121
12122
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)revslashspr[i][spr_extend],f))
12123 {
12124 new_return(23);
12125 }
12126 72 }
12127
12128
12129
2/2
✓ Branch 0 taken 2628 times.
✓ Branch 1 taken 18 times.
2646 for (int32_t q = 0; q < wMax; q++) // Hero defense values
12130 {
12131
1/2
✓ Branch 0 taken 2628 times.
✗ Branch 1 not taken.
2628 if (!p_putc(hero_defenses[q], f))
12132 new_return(15);
12133 2628 }
12134 //}
12135
12136
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
12137 {
12138 9 section_size=writesize;
12139 9 }
12140 18 }
12141
12142 //More data will come here
12143
12144
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
12145 {
12146 char ebuf[80];
12147 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
12148 jwin_alert("Error: writeherosprites()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
12149 }
12150
12151 9 new_return(0);
12152 }
12153
12154 9 int32_t writesubscreens(PACKFILE *f, zquestheader *Header)
12155 {
12156 9 dword section_id=ID_SUBSCREEN;
12157 9 dword section_version=V_SUBSCREEN;
12158 9 dword section_size=0;
12159
12160 //section id
12161
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
12162 {
12163 new_return(1);
12164 }
12165
12166 //section version info
12167
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
12168 {
12169 new_return(2);
12170 }
12171
12172
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!write_deprecated_section_cversion(section_version,f))
12173 {
12174 new_return(3);
12175 }
12176
12177
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
12178 {
12179 18 fake_pack_writing=(writecycle==0);
12180
12181 //section size
12182
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
12183 {
12184 new_return(4);
12185 }
12186
12187 18 writesize=0;
12188
12189 18 byte sz = subscreens_active.size();
12190
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(sz,f))
12191 new_return(5);
12192
2/2
✓ Branch 0 taken 86 times.
✓ Branch 1 taken 18 times.
104 for(int32_t i=0; i<sz; i++)
12193 {
12194 86 int32_t ret = subscreens_active[i].write(f);
12195 86 fake_pack_writing=(writecycle==0);
12196
12197
1/2
✓ Branch 0 taken 86 times.
✗ Branch 1 not taken.
86 if(ret!=0)
12198 new_return(ret);
12199 86 }
12200
12201 18 sz = subscreens_passive.size();
12202
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(sz,f))
12203 new_return(5);
12204
2/2
✓ Branch 0 taken 64 times.
✓ Branch 1 taken 18 times.
82 for(int32_t i=0; i<sz; i++)
12205 {
12206 64 int32_t ret = subscreens_passive[i].write(f);
12207 64 fake_pack_writing=(writecycle==0);
12208
12209
1/2
✓ Branch 0 taken 64 times.
✗ Branch 1 not taken.
64 if(ret!=0)
12210 new_return(ret);
12211 64 }
12212
12213 18 sz = subscreens_overlay.size();
12214
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(sz,f))
12215 new_return(5);
12216
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 for(int32_t i=0; i<sz; i++)
12217 {
12218 int32_t ret = subscreens_overlay[i].write(f);
12219 fake_pack_writing=(writecycle==0);
12220
12221 if(ret!=0)
12222 new_return(ret);
12223 }
12224
12225 18 sz = subscreens_map.size();
12226
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(sz,f))
12227 new_return(5);
12228
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 for(int32_t i=0; i<sz; i++)
12229 {
12230 int32_t ret = subscreens_map[i].write(f);
12231 fake_pack_writing=(writecycle==0);
12232
12233 if(ret!=0)
12234 new_return(ret);
12235 }
12236
12237
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
12238 {
12239 9 section_size=writesize;
12240 9 }
12241 18 }
12242
12243
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
12244 {
12245 char ebuf[80];
12246 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
12247 jwin_alert("Error: writesubscreens()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
12248 }
12249
12250 9 new_return(0);
12251 9 }
12252
12253 extern script_data *ffscripts[NUMSCRIPTFFC];
12254 extern script_data *itemscripts[NUMSCRIPTITEM];
12255 extern script_data *guyscripts[NUMSCRIPTGUYS];
12256 extern script_data *lwpnscripts[NUMSCRIPTWEAPONS];
12257 extern script_data *ewpnscripts[NUMSCRIPTWEAPONS];
12258 extern script_data *globalscripts[NUMSCRIPTGLOBAL];
12259 extern script_data *genericscripts[NUMSCRIPTSGENERIC];
12260 extern script_data *playerscripts[NUMSCRIPTHERO];
12261 extern script_data *screenscripts[NUMSCRIPTSCREEN];
12262 extern script_data *dmapscripts[NUMSCRIPTSDMAP];
12263 extern script_data *itemspritescripts[NUMSCRIPTSITEMSPRITE];
12264 extern script_data *comboscripts[NUMSCRIPTSCOMBODATA];
12265 extern script_data *subscreenscripts[NUMSCRIPTSSUBSCREEN];
12266
12267 9 int32_t writeffscript(PACKFILE *f, zquestheader *Header)
12268 {
12269
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 6 times.
9 if (QMisc.zscript_last_compiled_version <= 26)
12270 3 return writeffscript_old(f, Header);
12271
12272 6 dword section_id = ID_FFSCRIPT;
12273 6 dword section_version = V_FFSCRIPT;
12274 6 dword section_size = 0;
12275 6 dword zasmmeta_version = METADATA_V;
12276 6 byte numscripts = 0;
12277 6 numscripts = numscripts; //to avoid unused variables warnings
12278
12279 //section id
12280
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
12281 {
12282 new_return(1);
12283 }
12284
12285 //section version info
12286
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
12287 {
12288 new_return(2);
12289 }
12290
12291
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!write_deprecated_section_cversion(section_version,f))
12292 {
12293 new_return(3);
12294 }
12295
12296
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(zasmmeta_version,f))
12297 {
12298 new_return(4);
12299 }
12300
12301
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 6 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
12302 {
12303 12 fake_pack_writing=(writecycle==0);
12304
12305 //section size
12306
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
12307 {
12308 new_return(5);
12309 }
12310
12311 12 writesize=0;
12312
12313 12 write_quest_zasm(f);
12314
12315
2/2
✓ Branch 0 taken 6144 times.
✓ Branch 1 taken 12 times.
6156 for(int32_t i=0; i<NUMSCRIPTFFC; i++)
12316 {
12317 6144 int32_t ret = write_one_ffscript(f, Header, i, ffscripts[i]);
12318
12319
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(ret!=0)
12320 {
12321 new_return(ret);
12322 }
12323 6144 }
12324
12325
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTITEM; i++)
12326 {
12327 3072 int32_t ret = write_one_ffscript(f, Header, i, itemscripts[i]);
12328
12329
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12330 {
12331 new_return(ret);
12332 }
12333 3072 }
12334
12335
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTGUYS; i++)
12336 {
12337 3072 int32_t ret = write_one_ffscript(f, Header, i, guyscripts[i]);
12338
12339
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12340 {
12341 new_return(ret);
12342 }
12343 3072 }
12344
12345
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 script_data *fake = new script_data(ScriptType::None, 0);
12346
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTWEAPONS; i++)
12347 {
12348 3072 int32_t ret = write_one_ffscript(f, Header, i, fake);
12349
12350
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12351 {
12352 new_return(ret);
12353 }
12354 3072 }
12355
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 delete fake;
12356
12357
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTSCREEN; i++)
12358 {
12359 3072 int32_t ret = write_one_ffscript(f, Header, i, screenscripts[i]);
12360
12361
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12362 {
12363 new_return(ret);
12364 }
12365 3072 }
12366
12367
2/2
✓ Branch 0 taken 96 times.
✓ Branch 1 taken 12 times.
108 for(int32_t i=0; i<NUMSCRIPTGLOBAL; i++)
12368 {
12369 96 int32_t ret = write_one_ffscript(f, Header, i, globalscripts[i]);
12370
12371
1/2
✓ Branch 0 taken 96 times.
✗ Branch 1 not taken.
96 if(ret!=0)
12372 {
12373 new_return(ret);
12374 }
12375 96 }
12376
12377
2/2
✓ Branch 0 taken 60 times.
✓ Branch 1 taken 12 times.
72 for(int32_t i=0; i<NUMSCRIPTHERO; i++)
12378 {
12379 60 int32_t ret = write_one_ffscript(f, Header, i, playerscripts[i]);
12380
12381
1/2
✓ Branch 0 taken 60 times.
✗ Branch 1 not taken.
60 if(ret!=0)
12382 {
12383 new_return(ret);
12384 }
12385 60 }
12386
12387
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTWEAPONS; i++)
12388 {
12389 3072 int32_t ret = write_one_ffscript(f, Header, i, lwpnscripts[i]);
12390
12391
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12392 {
12393 new_return(ret);
12394 }
12395 3072 }
12396
12397
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTWEAPONS; i++)
12398 {
12399 3072 int32_t ret = write_one_ffscript(f, Header, i, ewpnscripts[i]);
12400
12401
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12402 {
12403 new_return(ret);
12404 }
12405 3072 }
12406
12407
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTSDMAP; i++)
12408 {
12409 3072 int32_t ret = write_one_ffscript(f, Header, i, dmapscripts[i]);
12410
12411
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12412 {
12413 new_return(ret);
12414 }
12415 3072 }
12416
12417
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTSITEMSPRITE; i++)
12418 {
12419 3072 int32_t ret = write_one_ffscript(f, Header, i, itemspritescripts[i]);
12420
12421
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12422 {
12423 new_return(ret);
12424 }
12425 3072 }
12426
12427
2/2
✓ Branch 0 taken 6144 times.
✓ Branch 1 taken 12 times.
6156 for(int32_t i=0; i<NUMSCRIPTSCOMBODATA; i++)
12428 {
12429 6144 int32_t ret = write_one_ffscript(f, Header, i, comboscripts[i]);
12430
12431
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(ret!=0)
12432 {
12433 new_return(ret);
12434 }
12435 6144 }
12436
12437
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(NUMSCRIPTSGENERIC,f))
12438 {
12439 new_return(2000);
12440 }
12441
2/2
✓ Branch 0 taken 6144 times.
✓ Branch 1 taken 12 times.
6156 for(int32_t i=0; i<NUMSCRIPTSGENERIC; i++)
12442 {
12443 6144 int32_t ret = write_one_ffscript(f, Header, i, genericscripts[i]);
12444
12445
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(ret!=0)
12446 {
12447 new_return(ret);
12448 }
12449 6144 }
12450
12451
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(NUMSCRIPTSSUBSCREEN,f))
12452 {
12453 new_return(2001);
12454 }
12455
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTSSUBSCREEN; i++)
12456 {
12457 3072 int32_t ret = write_one_ffscript(f, Header, i, subscreenscripts[i]);
12458
12459
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12460 {
12461 new_return(ret);
12462 }
12463 3072 }
12464
12465
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputl((int32_t)zScript.size(), f))
12466 {
12467 new_return(2001);
12468 }
12469
12470
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!pfwrite((void *)zScript.c_str(), (int32_t)zScript.size(), f))
12471 {
12472 new_return(2002);
12473 }
12474
12475 12 word numffcbindings=0;
12476
12477
2/2
✓ Branch 0 taken 6132 times.
✓ Branch 1 taken 12 times.
6144 for(std::map<int32_t, script_slot_data >::iterator it = ffcmap.begin(); it != ffcmap.end(); it++)
12478 {
12479
2/2
✓ Branch 0 taken 5974 times.
✓ Branch 1 taken 158 times.
6132 if(it->second.scriptname != "")
12480 {
12481 158 numffcbindings++;
12482 158 }
12483 6132 }
12484
12485
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numffcbindings, f))
12486 {
12487 new_return(2003);
12488 }
12489
12490
2/2
✓ Branch 0 taken 6132 times.
✓ Branch 1 taken 12 times.
6144 for(std::map<int32_t, script_slot_data >::iterator it = ffcmap.begin(); it != ffcmap.end(); it++)
12491 {
12492
2/2
✓ Branch 0 taken 5974 times.
✓ Branch 1 taken 158 times.
6132 if(it->second.scriptname != "")
12493 {
12494
1/2
✓ Branch 0 taken 158 times.
✗ Branch 1 not taken.
158 if(!p_iputw(it->first,f))
12495 {
12496 new_return(2004);
12497 }
12498
12499
1/2
✓ Branch 0 taken 158 times.
✗ Branch 1 not taken.
158 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12500 {
12501 new_return(2005);
12502 }
12503
12504
1/2
✓ Branch 0 taken 158 times.
✗ Branch 1 not taken.
158 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12505 {
12506 new_return(2006);
12507 }
12508 158 }
12509 6132 }
12510
12511 12 word numglobalbindings=0;
12512
12513
2/2
✓ Branch 0 taken 96 times.
✓ Branch 1 taken 12 times.
108 for(std::map<int32_t, script_slot_data >::iterator it = globalmap.begin(); it != globalmap.end(); it++)
12514 {
12515
2/2
✓ Branch 0 taken 74 times.
✓ Branch 1 taken 22 times.
96 if(it->second.scriptname != "")
12516 {
12517 22 numglobalbindings++;
12518 22 }
12519 96 }
12520
12521
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numglobalbindings, f))
12522 {
12523 new_return(2007);
12524 }
12525
12526
2/2
✓ Branch 0 taken 96 times.
✓ Branch 1 taken 12 times.
108 for(std::map<int32_t, script_slot_data >::iterator it = globalmap.begin(); it != globalmap.end(); it++)
12527 {
12528
2/2
✓ Branch 0 taken 74 times.
✓ Branch 1 taken 22 times.
96 if(it->second.scriptname != "")
12529 {
12530
1/2
✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
22 if(!p_iputw(it->first,f))
12531 {
12532 new_return(2008);
12533 }
12534
12535
1/2
✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
22 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12536 {
12537 new_return(2009);
12538 }
12539
12540
1/2
✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
22 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12541 {
12542 new_return(2010);
12543 }
12544 22 }
12545 96 }
12546
12547 12 word numitembindings=0;
12548
12549
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = itemmap.begin(); it != itemmap.end(); it++)
12550 {
12551
2/2
✓ Branch 0 taken 3034 times.
✓ Branch 1 taken 26 times.
3060 if(it->second.scriptname != "")
12552 {
12553 26 numitembindings++;
12554 26 }
12555 3060 }
12556
12557
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numitembindings, f))
12558 {
12559 new_return(2011);
12560 }
12561
12562
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = itemmap.begin(); it != itemmap.end(); it++)
12563 {
12564
2/2
✓ Branch 0 taken 3034 times.
✓ Branch 1 taken 26 times.
3060 if(it->second.scriptname != "")
12565 {
12566
1/2
✓ Branch 0 taken 26 times.
✗ Branch 1 not taken.
26 if(!p_iputw(it->first,f))
12567 {
12568 new_return(2012);
12569 }
12570
12571
1/2
✓ Branch 0 taken 26 times.
✗ Branch 1 not taken.
26 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12572 {
12573 new_return(2013);
12574 }
12575
12576
1/2
✓ Branch 0 taken 26 times.
✗ Branch 1 not taken.
26 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12577 {
12578 new_return(2014);
12579 }
12580 26 }
12581 3060 }
12582
12583 //new script types
12584 //npc scripts
12585 12 word numnpcbindings=0;
12586
12587
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = npcmap.begin(); it != npcmap.end(); it++)
12588 {
12589
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
12590 {
12591 numnpcbindings++;
12592 }
12593 3060 }
12594
12595
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numnpcbindings, f))
12596 {
12597 new_return(2015);
12598 }
12599
12600
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = npcmap.begin(); it != npcmap.end(); it++)
12601 {
12602
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
12603 {
12604 if(!p_iputw(it->first,f))
12605 {
12606 new_return(2016);
12607 }
12608
12609 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12610 {
12611 new_return(2017);
12612 }
12613
12614 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12615 {
12616 new_return(2018);
12617 }
12618 }
12619 3060 }
12620
12621 //lweapon
12622
12623 12 word numlwpnbindings=0;
12624
12625
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = lwpnmap.begin(); it != lwpnmap.end(); it++)
12626 {
12627
2/2
✓ Branch 0 taken 3058 times.
✓ Branch 1 taken 2 times.
3060 if(it->second.scriptname != "")
12628 {
12629 2 numlwpnbindings++;
12630 2 }
12631 3060 }
12632
12633
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numlwpnbindings, f))
12634 {
12635 new_return(2019);
12636 }
12637
12638
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = lwpnmap.begin(); it != lwpnmap.end(); it++)
12639 {
12640
2/2
✓ Branch 0 taken 3058 times.
✓ Branch 1 taken 2 times.
3060 if(it->second.scriptname != "")
12641 {
12642
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if(!p_iputw(it->first,f))
12643 {
12644 new_return(2020);
12645 }
12646
12647
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12648 {
12649 new_return(2021);
12650 }
12651
12652
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12653 {
12654 new_return(2022);
12655 }
12656 2 }
12657 3060 }
12658
12659 //////
12660
12661 //eweapon
12662
12663
12664 12 word numewpnbindings=0;
12665
12666
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = ewpnmap.begin(); it != ewpnmap.end(); it++)
12667 {
12668
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
12669 {
12670 numewpnbindings++;
12671 }
12672 3060 }
12673
12674
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numewpnbindings, f))
12675 {
12676 new_return(2023);
12677 }
12678
12679
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = ewpnmap.begin(); it != ewpnmap.end(); it++)
12680 {
12681
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
12682 {
12683 if(!p_iputw(it->first,f))
12684 {
12685 new_return(2024);
12686 }
12687
12688 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12689 {
12690 new_return(2025);
12691 }
12692
12693 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12694 {
12695 new_return(2026);
12696 }
12697 }
12698 3060 }
12699
12700 //player scripts
12701 12 word numherobindings=0;
12702
12703
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(std::map<int32_t, script_slot_data >::iterator it = playermap.begin(); it != playermap.end(); it++)
12704 {
12705
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(it->second.scriptname != "")
12706 {
12707 numherobindings++;
12708 }
12709 48 }
12710
12711
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numherobindings, f))
12712 {
12713 new_return(2027);
12714 }
12715
12716
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(std::map<int32_t, script_slot_data >::iterator it = playermap.begin(); it != playermap.end(); it++)
12717 {
12718
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(it->second.scriptname != "")
12719 {
12720 if(!p_iputw(it->first,f))
12721 {
12722 new_return(2028);
12723 }
12724
12725 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12726 {
12727 new_return(2029);
12728 }
12729
12730 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12731 {
12732 new_return(2030);
12733 }
12734 }
12735 48 }
12736
12737 //dmap scripts
12738 12 word numdmapbindings=0;
12739
12740
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = dmapmap.begin(); it != dmapmap.end(); it++)
12741 {
12742
2/2
✓ Branch 0 taken 3050 times.
✓ Branch 1 taken 10 times.
3060 if(it->second.scriptname != "")
12743 {
12744 10 numdmapbindings++;
12745 10 }
12746 3060 }
12747
12748
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numdmapbindings, f))
12749 {
12750 new_return(2031);
12751 }
12752
12753
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = dmapmap.begin(); it != dmapmap.end(); it++)
12754 {
12755
2/2
✓ Branch 0 taken 3050 times.
✓ Branch 1 taken 10 times.
3060 if(it->second.scriptname != "")
12756 {
12757
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 if(!p_iputw(it->first,f))
12758 {
12759 new_return(2032);
12760 }
12761
12762
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12763 {
12764 new_return(2033);
12765 }
12766
12767
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12768 {
12769 new_return(2034);
12770 }
12771 10 }
12772 3060 }
12773
12774 //screen scripts
12775 12 word numscreenbindings=0;
12776
12777
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = screenmap.begin(); it != screenmap.end(); it++)
12778 {
12779
2/2
✓ Branch 0 taken 3056 times.
✓ Branch 1 taken 4 times.
3060 if(it->second.scriptname != "")
12780 {
12781 4 numscreenbindings++;
12782 4 }
12783 3060 }
12784
12785
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numscreenbindings, f))
12786 {
12787 new_return(2035);
12788 }
12789
12790
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = screenmap.begin(); it != screenmap.end(); it++)
12791 {
12792
2/2
✓ Branch 0 taken 3056 times.
✓ Branch 1 taken 4 times.
3060 if(it->second.scriptname != "")
12793 {
12794
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 if(!p_iputw(it->first,f))
12795 {
12796 new_return(2036);
12797 }
12798
12799
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12800 {
12801 new_return(2037);
12802 }
12803
12804
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12805 {
12806 new_return(2038);
12807 }
12808 4 }
12809 3060 }
12810 //item sprite scripts
12811 12 word numitemspritebindings=0;
12812
12813
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = itemspritemap.begin(); it != itemspritemap.end(); it++)
12814 {
12815
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
12816 {
12817 numitemspritebindings++;
12818 }
12819 3060 }
12820
12821
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numitemspritebindings, f))
12822 {
12823 new_return(2039);
12824 }
12825
12826
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = itemspritemap.begin(); it != itemspritemap.end(); it++)
12827 {
12828
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
12829 {
12830 if(!p_iputw(it->first,f))
12831 {
12832 new_return(2040);
12833 }
12834
12835 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12836 {
12837 new_return(2041);
12838 }
12839
12840 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12841 {
12842 new_return(2042);
12843 }
12844 }
12845 3060 }
12846
12847 //combo scripts
12848 12 word numcombobindings=0;
12849
12850
2/2
✓ Branch 0 taken 6132 times.
✓ Branch 1 taken 12 times.
6144 for(std::map<int32_t, script_slot_data >::iterator it = comboscriptmap.begin(); it != comboscriptmap.end(); it++)
12851 {
12852
1/2
✓ Branch 0 taken 6132 times.
✗ Branch 1 not taken.
6132 if(it->second.scriptname != "")
12853 {
12854 numcombobindings++;
12855 }
12856 6132 }
12857
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numcombobindings, f))
12858 {
12859 new_return(2043);
12860 }
12861
12862
2/2
✓ Branch 0 taken 6132 times.
✓ Branch 1 taken 12 times.
6144 for(std::map<int32_t, script_slot_data >::iterator it = comboscriptmap.begin(); it != comboscriptmap.end(); it++)
12863 {
12864
1/2
✓ Branch 0 taken 6132 times.
✗ Branch 1 not taken.
6132 if(it->second.scriptname != "")
12865 {
12866 if(!p_iputw(it->first,f))
12867 {
12868 new_return(2044);
12869 }
12870
12871 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12872 {
12873 new_return(2045);
12874 }
12875
12876 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12877 {
12878 new_return(2046);
12879 }
12880 }
12881 6132 }
12882 //subscreen scripts
12883 12 word numgenericbindings=0;
12884
12885
2/2
✓ Branch 0 taken 6132 times.
✓ Branch 1 taken 12 times.
6144 for(auto it = genericmap.begin(); it != genericmap.end(); it++)
12886 {
12887
2/2
✓ Branch 0 taken 6090 times.
✓ Branch 1 taken 42 times.
6132 if(it->second.scriptname != "")
12888 {
12889 42 numgenericbindings++;
12890 42 }
12891 6132 }
12892
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numgenericbindings, f))
12893 {
12894 new_return(2043);
12895 }
12896
12897
2/2
✓ Branch 0 taken 6132 times.
✓ Branch 1 taken 12 times.
6144 for(auto it = genericmap.begin(); it != genericmap.end(); it++)
12898 {
12899
2/2
✓ Branch 0 taken 6090 times.
✓ Branch 1 taken 42 times.
6132 if(it->second.scriptname != "")
12900 {
12901
1/2
✓ Branch 0 taken 42 times.
✗ Branch 1 not taken.
42 if(!p_iputw(it->first,f))
12902 {
12903 new_return(2044);
12904 }
12905
12906
1/2
✓ Branch 0 taken 42 times.
✗ Branch 1 not taken.
42 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12907 {
12908 new_return(2045);
12909 }
12910
12911
1/2
✓ Branch 0 taken 42 times.
✗ Branch 1 not taken.
42 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12912 {
12913 new_return(2046);
12914 }
12915 42 }
12916 6132 }
12917
12918 //generic scripts
12919 12 word numsubscreenbindings=0;
12920
12921
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(auto it = subscreenmap.begin(); it != subscreenmap.end(); it++)
12922 {
12923
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
12924 {
12925 numsubscreenbindings++;
12926 }
12927 3060 }
12928
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numsubscreenbindings, f))
12929 {
12930 new_return(2047);
12931 }
12932
12933
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(auto it = subscreenmap.begin(); it != subscreenmap.end(); it++)
12934 {
12935
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
12936 {
12937 if(!p_iputw(it->first,f))
12938 {
12939 new_return(2048);
12940 }
12941
12942 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12943 {
12944 new_return(2049);
12945 }
12946
12947 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12948 {
12949 new_return(2050);
12950 }
12951 }
12952 3060 }
12953
12954
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
12955 {
12956 6 section_size=writesize;
12957 6 }
12958 12 }
12959
12960
12961
12962
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
12963 {
12964 char ebuf[80];
12965 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
12966 jwin_alert("Error: writeffscript()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
12967 }
12968
12969 6 new_return(0);
12970 //return 0; //this is just here to stomp the compiler from whining.
12971 //the irony is that it causes an "unreachable code" warning.
12972 9 }
12973
12974 12 int32_t write_quest_zasm(PACKFILE *f)
12975 {
12976 extern std::vector<std::shared_ptr<zasm_script>> zasm_scripts;
12977
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if (zasm_scripts.empty())
12978 {
12979 if(!p_iputl(0,f))
12980 new_return(1);
12981
12982 return 0;
12983 }
12984
12985 12 auto& zasm = zasm_scripts[0]->zasm;
12986 12 size_t num_commands = zasm.size();
12987
12988
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(num_commands,f))
12989 new_return(1);
12990
12991
2/2
✓ Branch 0 taken 372806 times.
✓ Branch 1 taken 12 times.
372818 for(int32_t j=0; j<num_commands; j++)
12992 {
12993 372806 auto& zas = zasm[j];
12994
12995
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 372806 times.
372806 if(zas.command==0xFFFF)
12996 continue;
12997 else
12998 {
12999
1/2
✓ Branch 0 taken 372806 times.
✗ Branch 1 not taken.
372806 if(!p_iputw(zas.command,f))
13000 new_return(2);
13001
13002
1/2
✓ Branch 0 taken 372806 times.
✗ Branch 1 not taken.
372806 if(!p_iputl(zas.arg1,f))
13003 new_return(3);
13004
13005
1/2
✓ Branch 0 taken 372806 times.
✗ Branch 1 not taken.
372806 if(!p_iputl(zas.arg2,f))
13006 new_return(4);
13007
13008
1/2
✓ Branch 0 taken 372806 times.
✗ Branch 1 not taken.
372806 if(!p_iputl(zas.arg3,f))
13009 new_return(5);
13010
13011 372806 uint32_t sz = 0;
13012
2/2
✓ Branch 0 taken 371822 times.
✓ Branch 1 taken 984 times.
372806 if(zas.strptr)
13013 984 sz = zas.strptr->size();
13014
1/2
✓ Branch 0 taken 372806 times.
✗ Branch 1 not taken.
372806 if(!p_iputl(sz,f))
13015 new_return(6);
13016
2/2
✓ Branch 0 taken 371834 times.
✓ Branch 1 taken 972 times.
372806 if(sz)
13017 {
13018 972 auto& str = *zas.strptr;
13019
2/2
✓ Branch 0 taken 20822 times.
✓ Branch 1 taken 972 times.
21794 for(size_t q = 0; q < sz; ++q)
13020 {
13021
1/2
✓ Branch 0 taken 20822 times.
✗ Branch 1 not taken.
20822 if(!p_putc(str[q],f))
13022 new_return(7);
13023 20822 }
13024 972 }
13025 372806 sz = 0;
13026
2/2
✓ Branch 0 taken 372598 times.
✓ Branch 1 taken 208 times.
372806 if(zas.vecptr)
13027 208 sz = zas.vecptr->size();
13028
1/2
✓ Branch 0 taken 372806 times.
✗ Branch 1 not taken.
372806 if(!p_iputl(sz,f))
13029 new_return(8);
13030
2/2
✓ Branch 0 taken 372598 times.
✓ Branch 1 taken 208 times.
372806 if(sz) //vector found
13031 {
13032 208 auto& vec = *zas.vecptr;
13033
2/2
✓ Branch 0 taken 1302 times.
✓ Branch 1 taken 208 times.
1510 for(size_t q = 0; q < sz; ++q)
13034 {
13035
1/2
✓ Branch 0 taken 1302 times.
✗ Branch 1 not taken.
1302 if(!p_iputl(vec[q],f))
13036 new_return(9);
13037 1302 }
13038 208 }
13039 }
13040 372806 }
13041 12 return 0;
13042 12 }
13043
13044 46236 int32_t write_one_ffscript(PACKFILE *f, zquestheader *, int32_t, script_data *script)
13045 {
13046
2/2
✓ Branch 0 taken 45986 times.
✓ Branch 1 taken 250 times.
46236 if (!script->valid())
13047 {
13048
1/2
✓ Branch 0 taken 45986 times.
✗ Branch 1 not taken.
45986 if (!p_putc(0, f))
13049 new_return(-1);
13050 45986 return 0;
13051 }
13052
13053
1/2
✓ Branch 0 taken 250 times.
✗ Branch 1 not taken.
250 if (!p_putc(1, f))
13054 new_return(-1);
13055
13056 250 zasm_meta const& tmeta = script->meta;
13057
1/2
✓ Branch 0 taken 250 times.
✗ Branch 1 not taken.
250 if(!p_iputw(tmeta.zasm_v,f))
13058 new_return(1);
13059
1/2
✓ Branch 0 taken 250 times.
✗ Branch 1 not taken.
250 if(!p_iputw(tmeta.meta_v,f))
13060 new_return(2);
13061
1/2
✓ Branch 0 taken 250 times.
✗ Branch 1 not taken.
250 if(!p_iputw(tmeta.ffscript_v,f))
13062 new_return(3);
13063
1/2
✓ Branch 0 taken 250 times.
✗ Branch 1 not taken.
250 if(!p_putc((int)tmeta.script_type,f))
13064 new_return(4);
13065
13066
2/2
✓ Branch 0 taken 2000 times.
✓ Branch 1 taken 250 times.
2250 for(int32_t q = 0; q < 8; ++q)
13067 {
13068
1/2
✓ Branch 0 taken 2000 times.
✗ Branch 1 not taken.
2000 if(!p_putcstr(tmeta.run_idens[q],f))
13069 new_return(5);
13070 2000 }
13071
13072
2/2
✓ Branch 0 taken 2000 times.
✓ Branch 1 taken 250 times.
2250 for(int32_t q = 0; q < 8; ++q)
13073
1/2
✓ Branch 0 taken 2000 times.
✗ Branch 1 not taken.
2000 if(!p_putc(tmeta.run_types[q],f))
13074 new_return(6);
13075
13076
1/2
✓ Branch 0 taken 250 times.
✗ Branch 1 not taken.
250 if(!p_putc(tmeta.flags,f))
13077 new_return(7);
13078
13079
1/2
✓ Branch 0 taken 250 times.
✗ Branch 1 not taken.
250 if(!p_iputw(tmeta.compiler_v1,f))
13080 new_return(8);
13081
13082
1/2
✓ Branch 0 taken 250 times.
✗ Branch 1 not taken.
250 if(!p_iputw(tmeta.compiler_v2,f))
13083 new_return(9);
13084
13085
1/2
✓ Branch 0 taken 250 times.
✗ Branch 1 not taken.
250 if(!p_iputw(tmeta.compiler_v3,f))
13086 new_return(10);
13087
13088
1/2
✓ Branch 0 taken 250 times.
✗ Branch 1 not taken.
250 if(!p_iputw(tmeta.compiler_v4,f))
13089 new_return(11);
13090
13091
1/2
✓ Branch 0 taken 250 times.
✗ Branch 1 not taken.
250 if(!p_putcstr(tmeta.script_name,f))
13092 new_return(12);
13093
1/2
✓ Branch 0 taken 250 times.
✗ Branch 1 not taken.
250 if(!p_putcstr(tmeta.author,f))
13094 new_return(13);
13095
2/2
✓ Branch 0 taken 2500 times.
✓ Branch 1 taken 250 times.
2750 for(auto q = 0; q < 10; ++q)
13096 {
13097
1/2
✓ Branch 0 taken 2500 times.
✗ Branch 1 not taken.
2500 if(!p_putcstr(tmeta.attributes[q],f))
13098 new_return(14);
13099
1/2
✓ Branch 0 taken 2500 times.
✗ Branch 1 not taken.
2500 if(!p_putwstr(tmeta.attributes_help[q],f))
13100 new_return(15);
13101 2500 }
13102
2/2
✓ Branch 0 taken 2000 times.
✓ Branch 1 taken 250 times.
2250 for(auto q = 0; q < 8; ++q)
13103 {
13104
1/2
✓ Branch 0 taken 2000 times.
✗ Branch 1 not taken.
2000 if(!p_putcstr(tmeta.attribytes[q],f))
13105 new_return(16);
13106
1/2
✓ Branch 0 taken 2000 times.
✗ Branch 1 not taken.
2000 if(!p_putwstr(tmeta.attribytes_help[q],f))
13107 new_return(17);
13108 2000 }
13109
2/2
✓ Branch 0 taken 2000 times.
✓ Branch 1 taken 250 times.
2250 for(auto q = 0; q < 8; ++q)
13110 {
13111
1/2
✓ Branch 0 taken 2000 times.
✗ Branch 1 not taken.
2000 if(!p_putcstr(tmeta.attrishorts[q],f))
13112 new_return(18);
13113
1/2
✓ Branch 0 taken 2000 times.
✗ Branch 1 not taken.
2000 if(!p_putwstr(tmeta.attrishorts_help[q],f))
13114 new_return(19);
13115 2000 }
13116
2/2
✓ Branch 0 taken 4000 times.
✓ Branch 1 taken 250 times.
4250 for(auto q = 0; q < 16; ++q)
13117 {
13118
1/2
✓ Branch 0 taken 4000 times.
✗ Branch 1 not taken.
4000 if(!p_putcstr(tmeta.usrflags[q],f))
13119 new_return(20);
13120
1/2
✓ Branch 0 taken 4000 times.
✗ Branch 1 not taken.
4000 if(!p_putwstr(tmeta.usrflags_help[q],f))
13121 new_return(21);
13122 4000 }
13123
2/2
✓ Branch 0 taken 2000 times.
✓ Branch 1 taken 250 times.
2250 for(auto q = 0; q < 8; ++q)
13124 {
13125
1/2
✓ Branch 0 taken 2000 times.
✗ Branch 1 not taken.
2000 if(!p_putcstr(tmeta.initd[q],f))
13126 new_return(22);
13127
1/2
✓ Branch 0 taken 2000 times.
✗ Branch 1 not taken.
2000 if(!p_putwstr(tmeta.initd_help[q],f))
13128 new_return(23);
13129 2000 }
13130
2/2
✓ Branch 0 taken 2000 times.
✓ Branch 1 taken 250 times.
2250 for(auto q = 0; q < 8; ++q)
13131 {
13132
1/2
✓ Branch 0 taken 2000 times.
✗ Branch 1 not taken.
2000 if(!p_putc(tmeta.initd_type[q],f))
13133 new_return(24);
13134 2000 }
13135
13136
1/2
✓ Branch 0 taken 250 times.
✗ Branch 1 not taken.
250 if(!p_iputl(script->pc, f))
13137 new_return(25);
13138
13139
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 250 times.
250 if(!p_iputl(script->end_pc, f))
13140 new_return(26);
13141
13142 250 return 0;
13143 46236 }
13144
13145
13146 3 int32_t writeffscript_old(PACKFILE *f, zquestheader *Header)
13147 {
13148 3 dword section_id = ID_FFSCRIPT;
13149 3 dword section_version = 26;
13150 3 dword section_cversion = 1;
13151 3 dword section_size = 0;
13152 3 dword zasmmeta_version = 5;
13153 3 byte numscripts = 0;
13154 3 numscripts = numscripts; //to avoid unused variables warnings
13155
13156 //section id
13157
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 if(!p_mputl(section_id,f))
13158 {
13159 new_return(1);
13160 }
13161
13162 //section version info
13163
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 if(!p_iputw(section_version,f))
13164 {
13165 new_return(2);
13166 }
13167
13168
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 if(!p_iputw(section_cversion,f))
13169 {
13170 new_return(3);
13171 }
13172
13173
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 if(!p_iputw(zasmmeta_version,f))
13174 {
13175 new_return(4);
13176 }
13177
13178
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 3 times.
9 for(int32_t writecycle=0; writecycle<2; ++writecycle)
13179 {
13180 6 fake_pack_writing=(writecycle==0);
13181
13182 //section size
13183
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputl(section_size,f))
13184 {
13185 new_return(5);
13186 }
13187
13188 6 writesize=0;
13189
13190
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 6 times.
3078 for(int32_t i=0; i<NUMSCRIPTFFC; i++)
13191 {
13192 3072 int32_t ret = write_one_ffscript_old(f, Header, i, ffscripts[i]);
13193 3072 fake_pack_writing=(writecycle==0);
13194
13195
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
13196 {
13197 new_return(ret);
13198 }
13199 3072 }
13200
13201
2/2
✓ Branch 0 taken 1536 times.
✓ Branch 1 taken 6 times.
1542 for(int32_t i=0; i<NUMSCRIPTITEM; i++)
13202 {
13203 1536 int32_t ret = write_one_ffscript_old(f, Header, i, itemscripts[i]);
13204 1536 fake_pack_writing=(writecycle==0);
13205
13206
1/2
✓ Branch 0 taken 1536 times.
✗ Branch 1 not taken.
1536 if(ret!=0)
13207 {
13208 new_return(ret);
13209 }
13210 1536 }
13211
13212
2/2
✓ Branch 0 taken 1536 times.
✓ Branch 1 taken 6 times.
1542 for(int32_t i=0; i<NUMSCRIPTGUYS; i++)
13213 {
13214 1536 int32_t ret = write_one_ffscript_old(f, Header, i, guyscripts[i]);
13215 1536 fake_pack_writing=(writecycle==0);
13216
13217
1/2
✓ Branch 0 taken 1536 times.
✗ Branch 1 not taken.
1536 if(ret!=0)
13218 {
13219 new_return(ret);
13220 }
13221 1536 }
13222
13223
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 script_data *fake = new script_data(ScriptType::None, 0);
13224
2/2
✓ Branch 0 taken 1536 times.
✓ Branch 1 taken 6 times.
1542 for(int32_t i=0; i<NUMSCRIPTWEAPONS; i++)
13225 {
13226 1536 int32_t ret = write_one_ffscript_old(f, Header, i, fake);
13227 1536 fake_pack_writing=(writecycle==0);
13228
13229
1/2
✓ Branch 0 taken 1536 times.
✗ Branch 1 not taken.
1536 if(ret!=0)
13230 {
13231 new_return(ret);
13232 }
13233 1536 }
13234
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 delete fake;
13235
13236
2/2
✓ Branch 0 taken 1536 times.
✓ Branch 1 taken 6 times.
1542 for(int32_t i=0; i<NUMSCRIPTSCREEN; i++)
13237 {
13238 1536 int32_t ret = write_one_ffscript_old(f, Header, i, screenscripts[i]);
13239 1536 fake_pack_writing=(writecycle==0);
13240
13241
1/2
✓ Branch 0 taken 1536 times.
✗ Branch 1 not taken.
1536 if(ret!=0)
13242 {
13243 new_return(ret);
13244 }
13245 1536 }
13246
13247
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 6 times.
54 for(int32_t i=0; i<NUMSCRIPTGLOBAL; i++)
13248 {
13249 48 int32_t ret = write_one_ffscript_old(f, Header, i, globalscripts[i]);
13250 48 fake_pack_writing=(writecycle==0);
13251
13252
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(ret!=0)
13253 {
13254 new_return(ret);
13255 }
13256 48 }
13257
13258
2/2
✓ Branch 0 taken 30 times.
✓ Branch 1 taken 6 times.
36 for(int32_t i=0; i<NUMSCRIPTHERO; i++)
13259 {
13260 30 int32_t ret = write_one_ffscript_old(f, Header, i, playerscripts[i]);
13261 30 fake_pack_writing=(writecycle==0);
13262
13263
1/2
✓ Branch 0 taken 30 times.
✗ Branch 1 not taken.
30 if(ret!=0)
13264 {
13265 new_return(ret);
13266 }
13267 30 }
13268
13269
2/2
✓ Branch 0 taken 1536 times.
✓ Branch 1 taken 6 times.
1542 for(int32_t i=0; i<NUMSCRIPTWEAPONS; i++)
13270 {
13271 1536 int32_t ret = write_one_ffscript_old(f, Header, i, lwpnscripts[i]);
13272 1536 fake_pack_writing=(writecycle==0);
13273
13274
1/2
✓ Branch 0 taken 1536 times.
✗ Branch 1 not taken.
1536 if(ret!=0)
13275 {
13276 new_return(ret);
13277 }
13278 1536 }
13279
13280
2/2
✓ Branch 0 taken 1536 times.
✓ Branch 1 taken 6 times.
1542 for(int32_t i=0; i<NUMSCRIPTWEAPONS; i++)
13281 {
13282 1536 int32_t ret = write_one_ffscript_old(f, Header, i, ewpnscripts[i]);
13283 1536 fake_pack_writing=(writecycle==0);
13284
13285
1/2
✓ Branch 0 taken 1536 times.
✗ Branch 1 not taken.
1536 if(ret!=0)
13286 {
13287 new_return(ret);
13288 }
13289 1536 }
13290
13291
2/2
✓ Branch 0 taken 1536 times.
✓ Branch 1 taken 6 times.
1542 for(int32_t i=0; i<NUMSCRIPTSDMAP; i++)
13292 {
13293 1536 int32_t ret = write_one_ffscript_old(f, Header, i, dmapscripts[i]);
13294 1536 fake_pack_writing=(writecycle==0);
13295
13296
1/2
✓ Branch 0 taken 1536 times.
✗ Branch 1 not taken.
1536 if(ret!=0)
13297 {
13298 new_return(ret);
13299 }
13300 1536 }
13301
13302
2/2
✓ Branch 0 taken 1536 times.
✓ Branch 1 taken 6 times.
1542 for(int32_t i=0; i<NUMSCRIPTSITEMSPRITE; i++)
13303 {
13304 1536 int32_t ret = write_one_ffscript_old(f, Header, i, itemspritescripts[i]);
13305 1536 fake_pack_writing=(writecycle==0);
13306
13307
1/2
✓ Branch 0 taken 1536 times.
✗ Branch 1 not taken.
1536 if(ret!=0)
13308 {
13309 new_return(ret);
13310 }
13311 1536 }
13312
13313
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 6 times.
3078 for(int32_t i=0; i<NUMSCRIPTSCOMBODATA; i++)
13314 {
13315 3072 int32_t ret = write_one_ffscript_old(f, Header, i, comboscripts[i]);
13316 3072 fake_pack_writing=(writecycle==0);
13317
13318
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
13319 {
13320 new_return(ret);
13321 }
13322 3072 }
13323
13324
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(NUMSCRIPTSGENERIC,f))
13325 {
13326 new_return(2000);
13327 }
13328
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 6 times.
3078 for(int32_t i=0; i<NUMSCRIPTSGENERIC; i++)
13329 {
13330 3072 int32_t ret = write_one_ffscript_old(f, Header, i, genericscripts[i]);
13331 3072 fake_pack_writing=(writecycle==0);
13332
13333
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
13334 {
13335 new_return(ret);
13336 }
13337 3072 }
13338
13339
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(NUMSCRIPTSSUBSCREEN,f))
13340 {
13341 new_return(2001);
13342 }
13343
2/2
✓ Branch 0 taken 1536 times.
✓ Branch 1 taken 6 times.
1542 for(int32_t i=0; i<NUMSCRIPTSSUBSCREEN; i++)
13344 {
13345 1536 int32_t ret = write_one_ffscript_old(f, Header, i, subscreenscripts[i]);
13346 1536 fake_pack_writing=(writecycle==0);
13347
13348
1/2
✓ Branch 0 taken 1536 times.
✗ Branch 1 not taken.
1536 if(ret!=0)
13349 {
13350 new_return(ret);
13351 }
13352 1536 }
13353
13354
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputl((int32_t)zScript.size(), f))
13355 {
13356 new_return(2001);
13357 }
13358
13359
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!pfwrite((void *)zScript.c_str(), (int32_t)zScript.size(), f))
13360 {
13361 new_return(2002);
13362 }
13363
13364 6 word numffcbindings=0;
13365
13366
2/2
✓ Branch 0 taken 3066 times.
✓ Branch 1 taken 6 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = ffcmap.begin(); it != ffcmap.end(); it++)
13367 {
13368
2/2
✓ Branch 0 taken 2860 times.
✓ Branch 1 taken 206 times.
3066 if(it->second.scriptname != "")
13369 {
13370 206 numffcbindings++;
13371 206 }
13372 3066 }
13373
13374
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(numffcbindings, f))
13375 {
13376 new_return(2003);
13377 }
13378
13379
2/2
✓ Branch 0 taken 3066 times.
✓ Branch 1 taken 6 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = ffcmap.begin(); it != ffcmap.end(); it++)
13380 {
13381
2/2
✓ Branch 0 taken 2860 times.
✓ Branch 1 taken 206 times.
3066 if(it->second.scriptname != "")
13382 {
13383
1/2
✓ Branch 0 taken 206 times.
✗ Branch 1 not taken.
206 if(!p_iputw(it->first,f))
13384 {
13385 new_return(2004);
13386 }
13387
13388
1/2
✓ Branch 0 taken 206 times.
✗ Branch 1 not taken.
206 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13389 {
13390 new_return(2005);
13391 }
13392
13393
1/2
✓ Branch 0 taken 206 times.
✗ Branch 1 not taken.
206 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13394 {
13395 new_return(2006);
13396 }
13397 206 }
13398 3066 }
13399
13400 6 word numglobalbindings=0;
13401
13402
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 6 times.
54 for(std::map<int32_t, script_slot_data >::iterator it = globalmap.begin(); it != globalmap.end(); it++)
13403 {
13404
2/2
✓ Branch 0 taken 30 times.
✓ Branch 1 taken 18 times.
48 if(it->second.scriptname != "")
13405 {
13406 18 numglobalbindings++;
13407 18 }
13408 48 }
13409
13410
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(numglobalbindings, f))
13411 {
13412 new_return(2007);
13413 }
13414
13415
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 6 times.
54 for(std::map<int32_t, script_slot_data >::iterator it = globalmap.begin(); it != globalmap.end(); it++)
13416 {
13417
2/2
✓ Branch 0 taken 30 times.
✓ Branch 1 taken 18 times.
48 if(it->second.scriptname != "")
13418 {
13419
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(it->first,f))
13420 {
13421 new_return(2008);
13422 }
13423
13424
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13425 {
13426 new_return(2009);
13427 }
13428
13429
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13430 {
13431 new_return(2010);
13432 }
13433 18 }
13434 48 }
13435
13436 6 word numitembindings=0;
13437
13438
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = itemmap.begin(); it != itemmap.end(); it++)
13439 {
13440
2/2
✓ Branch 0 taken 1512 times.
✓ Branch 1 taken 18 times.
1530 if(it->second.scriptname != "")
13441 {
13442 18 numitembindings++;
13443 18 }
13444 1530 }
13445
13446
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(numitembindings, f))
13447 {
13448 new_return(2011);
13449 }
13450
13451
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = itemmap.begin(); it != itemmap.end(); it++)
13452 {
13453
2/2
✓ Branch 0 taken 1512 times.
✓ Branch 1 taken 18 times.
1530 if(it->second.scriptname != "")
13454 {
13455
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(it->first,f))
13456 {
13457 new_return(2012);
13458 }
13459
13460
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13461 {
13462 new_return(2013);
13463 }
13464
13465
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13466 {
13467 new_return(2014);
13468 }
13469 18 }
13470 1530 }
13471
13472 //new script types
13473 //npc scripts
13474 6 word numnpcbindings=0;
13475
13476
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = npcmap.begin(); it != npcmap.end(); it++)
13477 {
13478
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 if(it->second.scriptname != "")
13479 {
13480 numnpcbindings++;
13481 }
13482 1530 }
13483
13484
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(numnpcbindings, f))
13485 {
13486 new_return(2015);
13487 }
13488
13489
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = npcmap.begin(); it != npcmap.end(); it++)
13490 {
13491
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 if(it->second.scriptname != "")
13492 {
13493 if(!p_iputw(it->first,f))
13494 {
13495 new_return(2016);
13496 }
13497
13498 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13499 {
13500 new_return(2017);
13501 }
13502
13503 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13504 {
13505 new_return(2018);
13506 }
13507 }
13508 1530 }
13509
13510 //lweapon
13511
13512 6 word numlwpnbindings=0;
13513
13514
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = lwpnmap.begin(); it != lwpnmap.end(); it++)
13515 {
13516
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 if(it->second.scriptname != "")
13517 {
13518 numlwpnbindings++;
13519 }
13520 1530 }
13521
13522
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(numlwpnbindings, f))
13523 {
13524 new_return(2019);
13525 }
13526
13527
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = lwpnmap.begin(); it != lwpnmap.end(); it++)
13528 {
13529
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 if(it->second.scriptname != "")
13530 {
13531 if(!p_iputw(it->first,f))
13532 {
13533 new_return(2020);
13534 }
13535
13536 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13537 {
13538 new_return(2021);
13539 }
13540
13541 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13542 {
13543 new_return(2022);
13544 }
13545 }
13546 1530 }
13547
13548 //////
13549
13550 //eweapon
13551
13552
13553 6 word numewpnbindings=0;
13554
13555
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = ewpnmap.begin(); it != ewpnmap.end(); it++)
13556 {
13557
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 if(it->second.scriptname != "")
13558 {
13559 numewpnbindings++;
13560 }
13561 1530 }
13562
13563
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(numewpnbindings, f))
13564 {
13565 new_return(2023);
13566 }
13567
13568
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = ewpnmap.begin(); it != ewpnmap.end(); it++)
13569 {
13570
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 if(it->second.scriptname != "")
13571 {
13572 if(!p_iputw(it->first,f))
13573 {
13574 new_return(2024);
13575 }
13576
13577 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13578 {
13579 new_return(2025);
13580 }
13581
13582 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13583 {
13584 new_return(2026);
13585 }
13586 }
13587 1530 }
13588
13589 //player scripts
13590 6 word numherobindings=0;
13591
13592
2/2
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 6 times.
30 for(std::map<int32_t, script_slot_data >::iterator it = playermap.begin(); it != playermap.end(); it++)
13593 {
13594
2/2
✓ Branch 0 taken 22 times.
✓ Branch 1 taken 2 times.
24 if(it->second.scriptname != "")
13595 {
13596 2 numherobindings++;
13597 2 }
13598 24 }
13599
13600
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(numherobindings, f))
13601 {
13602 new_return(2027);
13603 }
13604
13605
2/2
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 6 times.
30 for(std::map<int32_t, script_slot_data >::iterator it = playermap.begin(); it != playermap.end(); it++)
13606 {
13607
2/2
✓ Branch 0 taken 22 times.
✓ Branch 1 taken 2 times.
24 if(it->second.scriptname != "")
13608 {
13609
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if(!p_iputw(it->first,f))
13610 {
13611 new_return(2028);
13612 }
13613
13614
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13615 {
13616 new_return(2029);
13617 }
13618
13619
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13620 {
13621 new_return(2030);
13622 }
13623 2 }
13624 24 }
13625
13626 //dmap scripts
13627 6 word numdmapbindings=0;
13628
13629
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = dmapmap.begin(); it != dmapmap.end(); it++)
13630 {
13631
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 if(it->second.scriptname != "")
13632 {
13633 numdmapbindings++;
13634 }
13635 1530 }
13636
13637
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(numdmapbindings, f))
13638 {
13639 new_return(2031);
13640 }
13641
13642
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = dmapmap.begin(); it != dmapmap.end(); it++)
13643 {
13644
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 if(it->second.scriptname != "")
13645 {
13646 if(!p_iputw(it->first,f))
13647 {
13648 new_return(2032);
13649 }
13650
13651 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13652 {
13653 new_return(2033);
13654 }
13655
13656 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13657 {
13658 new_return(2034);
13659 }
13660 }
13661 1530 }
13662
13663 //screen scripts
13664 6 word numscreenbindings=0;
13665
13666
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = screenmap.begin(); it != screenmap.end(); it++)
13667 {
13668
2/2
✓ Branch 0 taken 1516 times.
✓ Branch 1 taken 14 times.
1530 if(it->second.scriptname != "")
13669 {
13670 14 numscreenbindings++;
13671 14 }
13672 1530 }
13673
13674
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(numscreenbindings, f))
13675 {
13676 new_return(2035);
13677 }
13678
13679
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = screenmap.begin(); it != screenmap.end(); it++)
13680 {
13681
2/2
✓ Branch 0 taken 1516 times.
✓ Branch 1 taken 14 times.
1530 if(it->second.scriptname != "")
13682 {
13683
1/2
✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
14 if(!p_iputw(it->first,f))
13684 {
13685 new_return(2036);
13686 }
13687
13688
1/2
✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
14 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13689 {
13690 new_return(2037);
13691 }
13692
13693
1/2
✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
14 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13694 {
13695 new_return(2038);
13696 }
13697 14 }
13698 1530 }
13699 //item sprite scripts
13700 6 word numitemspritebindings=0;
13701
13702
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = itemspritemap.begin(); it != itemspritemap.end(); it++)
13703 {
13704
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 if(it->second.scriptname != "")
13705 {
13706 numitemspritebindings++;
13707 }
13708 1530 }
13709
13710
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(numitemspritebindings, f))
13711 {
13712 new_return(2039);
13713 }
13714
13715
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = itemspritemap.begin(); it != itemspritemap.end(); it++)
13716 {
13717
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 if(it->second.scriptname != "")
13718 {
13719 if(!p_iputw(it->first,f))
13720 {
13721 new_return(2040);
13722 }
13723
13724 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13725 {
13726 new_return(2041);
13727 }
13728
13729 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13730 {
13731 new_return(2042);
13732 }
13733 }
13734 1530 }
13735
13736 //combo scripts
13737 6 word numcombobindings=0;
13738
13739
2/2
✓ Branch 0 taken 3066 times.
✓ Branch 1 taken 6 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = comboscriptmap.begin(); it != comboscriptmap.end(); it++)
13740 {
13741
1/2
✓ Branch 0 taken 3066 times.
✗ Branch 1 not taken.
3066 if(it->second.scriptname != "")
13742 {
13743 numcombobindings++;
13744 }
13745 3066 }
13746
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(numcombobindings, f))
13747 {
13748 new_return(2043);
13749 }
13750
13751
2/2
✓ Branch 0 taken 3066 times.
✓ Branch 1 taken 6 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = comboscriptmap.begin(); it != comboscriptmap.end(); it++)
13752 {
13753
1/2
✓ Branch 0 taken 3066 times.
✗ Branch 1 not taken.
3066 if(it->second.scriptname != "")
13754 {
13755 if(!p_iputw(it->first,f))
13756 {
13757 new_return(2044);
13758 }
13759
13760 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13761 {
13762 new_return(2045);
13763 }
13764
13765 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13766 {
13767 new_return(2046);
13768 }
13769 }
13770 3066 }
13771 //subscreen scripts
13772 6 word numgenericbindings=0;
13773
13774
2/2
✓ Branch 0 taken 3066 times.
✓ Branch 1 taken 6 times.
3072 for(auto it = genericmap.begin(); it != genericmap.end(); it++)
13775 {
13776
1/2
✓ Branch 0 taken 3066 times.
✗ Branch 1 not taken.
3066 if(it->second.scriptname != "")
13777 {
13778 numgenericbindings++;
13779 }
13780 3066 }
13781
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(numgenericbindings, f))
13782 {
13783 new_return(2043);
13784 }
13785
13786
2/2
✓ Branch 0 taken 3066 times.
✓ Branch 1 taken 6 times.
3072 for(auto it = genericmap.begin(); it != genericmap.end(); it++)
13787 {
13788
1/2
✓ Branch 0 taken 3066 times.
✗ Branch 1 not taken.
3066 if(it->second.scriptname != "")
13789 {
13790 if(!p_iputw(it->first,f))
13791 {
13792 new_return(2044);
13793 }
13794
13795 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13796 {
13797 new_return(2045);
13798 }
13799
13800 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13801 {
13802 new_return(2046);
13803 }
13804 }
13805 3066 }
13806
13807 //generic scripts
13808 6 word numsubscreenbindings=0;
13809
13810
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(auto it = subscreenmap.begin(); it != subscreenmap.end(); it++)
13811 {
13812
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 if(it->second.scriptname != "")
13813 {
13814 numsubscreenbindings++;
13815 }
13816 1530 }
13817
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(numsubscreenbindings, f))
13818 {
13819 new_return(2047);
13820 }
13821
13822
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(auto it = subscreenmap.begin(); it != subscreenmap.end(); it++)
13823 {
13824
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 if(it->second.scriptname != "")
13825 {
13826 if(!p_iputw(it->first,f))
13827 {
13828 new_return(2048);
13829 }
13830
13831 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13832 {
13833 new_return(2049);
13834 }
13835
13836 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13837 {
13838 new_return(2050);
13839 }
13840 }
13841 1530 }
13842
13843
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 3 times.
6 if(writecycle==0)
13844 {
13845 3 section_size=writesize;
13846 3 }
13847 6 }
13848
13849
13850
13851
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
3 if(writesize!=int32_t(section_size) && save_warn)
13852 {
13853 char ebuf[80];
13854 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
13855 jwin_alert("Error: writeffscript()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
13856 }
13857
13858 3 new_return(0);
13859 //return 0; //this is just here to stomp the compiler from whining.
13860 //the irony is that it causes an "unreachable code" warning.
13861 3 }
13862
13863 23118 int32_t write_one_ffscript_old(PACKFILE *f, zquestheader *Header, int32_t i, script_data *script)
13864 {
13865 //these are here to bypass compiler warnings about unused arguments
13866 23118 Header=Header;
13867 23118 i=i;
13868
13869
2/2
✓ Branch 0 taken 11830 times.
✓ Branch 1 taken 11288 times.
23118 size_t num_commands = script->zasm_script ? script->zasm_script->size : 0;
13870
13871
1/2
✓ Branch 0 taken 23118 times.
✗ Branch 1 not taken.
23118 if(!p_iputl(num_commands,f))
13872 {
13873 new_return(6);
13874 }
13875
13876 //Metadata
13877 23118 zasm_meta const& tmeta = script->meta;
13878
1/2
✓ Branch 0 taken 23118 times.
✗ Branch 1 not taken.
23118 if(!p_iputw(tmeta.zasm_v,f))
13879 {
13880 new_return(7);
13881 }
13882
13883
1/2
✓ Branch 0 taken 23118 times.
✗ Branch 1 not taken.
23118 if(!p_iputw(tmeta.meta_v,f))
13884 {
13885 new_return(8);
13886 }
13887
13888
1/2
✓ Branch 0 taken 23118 times.
✗ Branch 1 not taken.
23118 if(!p_iputw(tmeta.ffscript_v,f))
13889 {
13890 new_return(9);
13891 }
13892
13893
1/2
✓ Branch 0 taken 23118 times.
✗ Branch 1 not taken.
23118 if(!p_putc((int)tmeta.script_type,f))
13894 {
13895 new_return(10);
13896 }
13897
13898
2/2
✓ Branch 0 taken 184944 times.
✓ Branch 1 taken 23118 times.
208062 for(int32_t q = 0; q < 8; ++q)
13899 {
13900
1/2
✓ Branch 0 taken 184944 times.
✗ Branch 1 not taken.
184944 if(!p_putcstr(tmeta.run_idens[q],f))
13901 new_return(11);
13902 184944 }
13903
13904
2/2
✓ Branch 0 taken 184944 times.
✓ Branch 1 taken 23118 times.
208062 for(int32_t q = 0; q < 8; ++q)
13905 {
13906
1/2
✓ Branch 0 taken 184944 times.
✗ Branch 1 not taken.
184944 if(!p_putc(tmeta.run_types[q],f))
13907 {
13908 new_return(12);
13909 }
13910 184944 }
13911
13912
1/2
✓ Branch 0 taken 23118 times.
✗ Branch 1 not taken.
23118 if(!p_putc(tmeta.flags,f))
13913 {
13914 new_return(13);
13915 }
13916
13917
1/2
✓ Branch 0 taken 23118 times.
✗ Branch 1 not taken.
23118 if(!p_iputw(tmeta.compiler_v1,f))
13918 {
13919 new_return(14);
13920 }
13921
13922
1/2
✓ Branch 0 taken 23118 times.
✗ Branch 1 not taken.
23118 if(!p_iputw(tmeta.compiler_v2,f))
13923 {
13924 new_return(15);
13925 }
13926
13927
1/2
✓ Branch 0 taken 23118 times.
✗ Branch 1 not taken.
23118 if(!p_iputw(tmeta.compiler_v3,f))
13928 {
13929 new_return(16);
13930 }
13931
13932
1/2
✓ Branch 0 taken 23118 times.
✗ Branch 1 not taken.
23118 if(!p_iputw(tmeta.compiler_v4,f))
13933 {
13934 new_return(17);
13935 }
13936
13937
1/2
✓ Branch 0 taken 23118 times.
✗ Branch 1 not taken.
23118 if(!p_putcstr(tmeta.script_name,f))
13938 new_return(18);
13939
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 23118 times.
23118 if(!p_putcstr(tmeta.author,f))
13940 new_return(19);
13941
2/2
✓ Branch 0 taken 231180 times.
✓ Branch 1 taken 23118 times.
254298 for(auto q = 0; q < 10; ++q)
13942 {
13943
1/2
✓ Branch 0 taken 231180 times.
✗ Branch 1 not taken.
231180 if(!p_putcstr(tmeta.attributes[q],f))
13944 new_return(27);
13945
1/2
✓ Branch 0 taken 231180 times.
✗ Branch 1 not taken.
231180 if(!p_putwstr(tmeta.attributes_help[q],f))
13946 new_return(28);
13947 231180 }
13948
2/2
✓ Branch 0 taken 184944 times.
✓ Branch 1 taken 23118 times.
208062 for(auto q = 0; q < 8; ++q)
13949 {
13950
1/2
✓ Branch 0 taken 184944 times.
✗ Branch 1 not taken.
184944 if(!p_putcstr(tmeta.attribytes[q],f))
13951 new_return(29);
13952
1/2
✓ Branch 0 taken 184944 times.
✗ Branch 1 not taken.
184944 if(!p_putwstr(tmeta.attribytes_help[q],f))
13953 new_return(30);
13954 184944 }
13955
2/2
✓ Branch 0 taken 184944 times.
✓ Branch 1 taken 23118 times.
208062 for(auto q = 0; q < 8; ++q)
13956 {
13957
1/2
✓ Branch 0 taken 184944 times.
✗ Branch 1 not taken.
184944 if(!p_putcstr(tmeta.attrishorts[q],f))
13958 new_return(31);
13959
1/2
✓ Branch 0 taken 184944 times.
✗ Branch 1 not taken.
184944 if(!p_putwstr(tmeta.attrishorts_help[q],f))
13960 new_return(32);
13961 184944 }
13962
2/2
✓ Branch 0 taken 369888 times.
✓ Branch 1 taken 23118 times.
393006 for(auto q = 0; q < 16; ++q)
13963 {
13964
1/2
✓ Branch 0 taken 369888 times.
✗ Branch 1 not taken.
369888 if(!p_putcstr(tmeta.usrflags[q],f))
13965 new_return(33);
13966
1/2
✓ Branch 0 taken 369888 times.
✗ Branch 1 not taken.
369888 if(!p_putwstr(tmeta.usrflags_help[q],f))
13967 new_return(34);
13968 369888 }
13969
2/2
✓ Branch 0 taken 184944 times.
✓ Branch 1 taken 23118 times.
208062 for(auto q = 0; q < 8; ++q)
13970 {
13971
1/2
✓ Branch 0 taken 184944 times.
✗ Branch 1 not taken.
184944 if(!p_putcstr(tmeta.initd[q],f))
13972 new_return(35);
13973
1/2
✓ Branch 0 taken 184944 times.
✗ Branch 1 not taken.
184944 if(!p_putwstr(tmeta.initd_help[q],f))
13974 new_return(36);
13975 184944 }
13976
2/2
✓ Branch 0 taken 184944 times.
✓ Branch 1 taken 23118 times.
208062 for(auto q = 0; q < 8; ++q)
13977 {
13978
1/2
✓ Branch 0 taken 184944 times.
✗ Branch 1 not taken.
184944 if(!p_putc(tmeta.initd_type[q],f))
13979 new_return(37);
13980 184944 }
13981
13982
2/2
✓ Branch 0 taken 11288 times.
✓ Branch 1 taken 2056888 times.
2068176 for(int32_t j=0; j<num_commands; j++)
13983 {
13984 2056888 auto& zas = script->zasm_script->zasm[j];
13985
1/2
✓ Branch 0 taken 2056888 times.
✗ Branch 1 not taken.
2056888 if(!p_iputw(zas.command,f))
13986 {
13987 new_return(20);
13988 }
13989
13990
2/2
✓ Branch 0 taken 2045058 times.
✓ Branch 1 taken 11830 times.
2056888 if(zas.command==0xFFFF)
13991 {
13992 11830 break;
13993 }
13994 else
13995 {
13996
1/2
✓ Branch 0 taken 2045058 times.
✗ Branch 1 not taken.
2045058 if(!p_iputl(zas.arg1,f))
13997 {
13998 new_return(21);
13999 }
14000
14001
1/2
✓ Branch 0 taken 2045058 times.
✗ Branch 1 not taken.
2045058 if(!p_iputl(zas.arg2,f))
14002 {
14003 new_return(22);
14004 }
14005
14006
1/2
✓ Branch 0 taken 2045058 times.
✗ Branch 1 not taken.
2045058 if(!p_iputl(zas.arg3,f))
14007 {
14008 new_return(23);
14009 }
14010
14011 2045058 uint32_t sz = 0;
14012
2/2
✓ Branch 0 taken 2340 times.
✓ Branch 1 taken 2042718 times.
2045058 if(zas.strptr)
14013 2340 sz = zas.strptr->size();
14014
1/2
✓ Branch 0 taken 2045058 times.
✗ Branch 1 not taken.
2045058 if(!p_iputl(sz,f))
14015 {
14016 new_return(23);
14017 }
14018
2/2
✓ Branch 0 taken 2042718 times.
✓ Branch 1 taken 2340 times.
2045058 if(sz)
14019 {
14020 2340 auto& str = *zas.strptr;
14021
2/2
✓ Branch 0 taken 214720 times.
✓ Branch 1 taken 2340 times.
217060 for(size_t q = 0; q < sz; ++q)
14022 {
14023
1/2
✓ Branch 0 taken 214720 times.
✗ Branch 1 not taken.
214720 if(!p_putc(str[q],f))
14024 {
14025 new_return(24);
14026 }
14027 214720 }
14028 2340 }
14029 2045058 sz = 0;
14030
2/2
✓ Branch 0 taken 2045036 times.
✓ Branch 1 taken 22 times.
2045058 if(zas.vecptr)
14031 22 sz = zas.vecptr->size();
14032
1/2
✓ Branch 0 taken 2045058 times.
✗ Branch 1 not taken.
2045058 if(!p_iputl(sz,f))
14033 {
14034 new_return(25);
14035 }
14036
2/2
✓ Branch 0 taken 2045036 times.
✓ Branch 1 taken 22 times.
2045058 if(sz) //vector found
14037 {
14038 22 auto& vec = *zas.vecptr;
14039
2/2
✓ Branch 0 taken 352 times.
✓ Branch 1 taken 22 times.
374 for(size_t q = 0; q < sz; ++q)
14040 {
14041
1/2
✓ Branch 0 taken 352 times.
✗ Branch 1 not taken.
352 if(!p_iputl(vec[q],f))
14042 {
14043 new_return(26);
14044 }
14045 352 }
14046 22 }
14047 }
14048 2045058 }
14049
14050 23118 new_return(0);
14051 }
14052
14053 extern SAMPLE customsfxdata[WAV_COUNT];
14054 extern uint8_t customsfxflag[WAV_COUNT>>3];
14055
14056 9 int32_t writesfx(PACKFILE *f, zquestheader *Header)
14057 {
14058 //these are here to bypass compiler warnings about unused arguments
14059 9 Header=Header;
14060
14061 9 dword section_id=ID_SFX;
14062 9 dword section_version=V_SFX;
14063 9 dword section_size=0;
14064
14065 //section id
14066
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
14067 {
14068 new_return(1);
14069 }
14070
14071 //section version info
14072
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
14073 {
14074 new_return(2);
14075 }
14076
14077
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
14078 {
14079 new_return(3);
14080 }
14081
14082
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 18 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
14083 {
14084 18 fake_pack_writing=(writecycle==0);
14085
14086 //section size
14087
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
14088 {
14089 new_return(4);
14090 }
14091
14092 18 writesize=0;
14093
14094
2/2
✓ Branch 0 taken 576 times.
✓ Branch 1 taken 18 times.
594 for(int32_t i=0; i<WAV_COUNT>>3; i++)
14095 {
14096
1/2
✓ Branch 0 taken 576 times.
✗ Branch 1 not taken.
576 if(!p_putc(customsfxflag[i],f))
14097 {
14098 new_return(5);
14099 }
14100 576 }
14101
14102
2/2
✓ Branch 0 taken 4590 times.
✓ Branch 1 taken 18 times.
4608 for(int32_t i=1; i<WAV_COUNT; i++)
14103 {
14104
2/2
✓ Branch 0 taken 1260 times.
✓ Branch 1 taken 3330 times.
4590 if(get_bit(customsfxflag, i-1) == 0)
14105 3330 continue;
14106
14107
1/2
✓ Branch 0 taken 1260 times.
✗ Branch 1 not taken.
1260 if(!pfwrite(sfx_string[i], 36, f))
14108 {
14109 new_return(5);
14110 }
14111 1260 }
14112
14113
2/2
✓ Branch 0 taken 4590 times.
✓ Branch 1 taken 18 times.
4608 for(int32_t i=1; i<WAV_COUNT; i++)
14114 {
14115
2/2
✓ Branch 0 taken 1260 times.
✓ Branch 1 taken 3330 times.
4590 if(get_bit(customsfxflag, i-1) == 0)
14116 3330 continue;
14117
14118
1/2
✓ Branch 0 taken 1260 times.
✗ Branch 1 not taken.
1260 if(!p_iputl(customsfxdata[i].bits,f))
14119 {
14120 new_return(5);
14121 }
14122
14123
1/2
✓ Branch 0 taken 1260 times.
✗ Branch 1 not taken.
1260 if(!p_iputl(customsfxdata[i].stereo,f))
14124 {
14125 new_return(6);
14126 }
14127
14128
1/2
✓ Branch 0 taken 1260 times.
✗ Branch 1 not taken.
1260 if(!p_iputl(customsfxdata[i].freq,f))
14129 {
14130 new_return(7);
14131 }
14132
14133
1/2
✓ Branch 0 taken 1260 times.
✗ Branch 1 not taken.
1260 if(!p_iputl(customsfxdata[i].priority,f))
14134 {
14135 new_return(8);
14136 }
14137
14138
1/2
✓ Branch 0 taken 1260 times.
✗ Branch 1 not taken.
1260 if(!p_iputl(customsfxdata[i].len,f))
14139 {
14140 new_return(9);
14141 }
14142
14143
1/2
✓ Branch 0 taken 1260 times.
✗ Branch 1 not taken.
1260 if(!p_iputl(customsfxdata[i].loop_start,f))
14144 {
14145 new_return(10);
14146 }
14147
14148
1/2
✓ Branch 0 taken 1260 times.
✗ Branch 1 not taken.
1260 if(!p_iputl(customsfxdata[i].loop_end,f))
14149 {
14150 new_return(11);
14151 }
14152
14153
1/2
✓ Branch 0 taken 1260 times.
✗ Branch 1 not taken.
1260 if(!p_iputl(customsfxdata[i].param,f))
14154 {
14155 new_return(12);
14156 }
14157
14158 //de-endianfy the data
14159 1260 int32_t wordstowrite = (customsfxdata[i].bits==8?1:2)*(customsfxdata[i].stereo==0?1:2)*customsfxdata[i].len/sizeof(word);
14160
14161
2/2
✓ Branch 0 taken 28596352 times.
✓ Branch 1 taken 1260 times.
28597612 for(int32_t j=0; j<wordstowrite; j++)
14162 {
14163
1/2
✓ Branch 0 taken 28596352 times.
✗ Branch 1 not taken.
28596352 if(!p_iputw(((word *)customsfxdata[i].data)[j],f))
14164 {
14165 new_return(13);
14166 }
14167 28596352 }
14168 1260 }
14169
14170
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
14171 {
14172 9 section_size=writesize;
14173 9 }
14174 18 }
14175
14176
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
14177 {
14178 char ebuf[80];
14179 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
14180 jwin_alert("Error: writesfx()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
14181 }
14182
14183 9 new_return(0);
14184 }
14185
14186 9 int32_t writeinitdata(PACKFILE *f, zquestheader *)
14187 {
14188 9 dword section_id=ID_INITDATA;
14189 9 dword section_version=V_INITDATA;
14190 9 dword section_size = 0;
14191
14192 9 zinit.last_map=Map.getCurrMap();
14193 9 zinit.last_screen=Map.getCurrScr();
14194 9 zinit.normalize();
14195
14196 //section id
14197
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
14198 {
14199 new_return(1);
14200 }
14201
14202 //section version info
14203
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
14204 {
14205 new_return(2);
14206 }
14207
14208
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
14209 {
14210 new_return(3);
14211 }
14212
14213 //TODO
14214
14215
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 18 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
14216 {
14217 18 fake_pack_writing=(writecycle==0);
14218
14219 //section size
14220
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
14221 new_return(4);
14222
14223 18 writesize=0;
14224
14225
2/2
✓ Branch 0 taken 576 times.
✓ Branch 1 taken 18 times.
594 for(int q = 0; q < MAXITEMS/8; ++q)
14226
1/2
✓ Branch 0 taken 576 times.
✗ Branch 1 not taken.
576 if(!p_putc(zinit.items[q], f))
14227 new_return(5);
14228
2/2
✓ Branch 0 taken 9216 times.
✓ Branch 1 taken 18 times.
9234 for(int q = 0; q < MAXLEVELS; ++q)
14229 {
14230
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(zinit.litems[q], f))
14231 new_return(6);
14232 9216 }
14233
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putbvec(zinit.level_keys, f))
14234 new_return(10);
14235
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(MAX_COUNTERS,f))
14236 new_return(11);
14237
2/2
✓ Branch 0 taken 1926 times.
✓ Branch 1 taken 18 times.
1944 for(int q = 0; q < MAX_COUNTERS; ++q)
14238
1/2
✓ Branch 0 taken 1926 times.
✗ Branch 1 not taken.
1926 if(!p_iputw(zinit.counter[q],f))
14239 new_return(12);
14240
2/2
✓ Branch 0 taken 1926 times.
✓ Branch 1 taken 18 times.
1944 for(int q = 0; q < MAX_COUNTERS; ++q)
14241
1/2
✓ Branch 0 taken 1926 times.
✗ Branch 1 not taken.
1926 if(!p_iputw(zinit.mcounter[q],f))
14242 new_return(13);
14243
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.bomb_ratio,f))
14244 new_return(14);
14245
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.hcp,f))
14246 new_return(15);
14247
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.hcp_per_hc,f))
14248 new_return(16);
14249
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(zinit.cont_heart,f))
14250 new_return(17);
14251
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.hp_per_heart,f))
14252 new_return(18);
14253
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.magic_per_block,f))
14254 new_return(19);
14255
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.hero_damage_multiplier,f))
14256 new_return(20);
14257
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.ene_damage_multiplier,f))
14258 new_return(21);
14259
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.dither_type,f))
14260 new_return(22);
14261
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.dither_arg,f))
14262 new_return(23);
14263
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.dither_percent,f))
14264 new_return(24);
14265
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.def_lightrad,f))
14266 new_return(25);
14267
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.transdark_percent,f))
14268 new_return(26);
14269
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.darkcol,f))
14270 new_return(27);
14271
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(zinit.ss_grid_x,f))
14272 new_return(28);
14273
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(zinit.ss_grid_y,f))
14274 new_return(29);
14275
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(zinit.ss_grid_xofs,f))
14276 new_return(30);
14277
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(zinit.ss_grid_yofs,f))
14278 new_return(31);
14279
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(zinit.ss_grid_color,f))
14280 new_return(32);
14281
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(zinit.ss_bbox_1_color,f))
14282 new_return(33);
14283
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(zinit.ss_bbox_2_color,f))
14284 new_return(34);
14285
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(zinit.ss_flags,f))
14286 new_return(35);
14287
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putbitstr(zinit.flags,f))
14288 new_return(36);
14289
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.last_map,f))
14290 new_return(37);
14291
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.last_screen,f))
14292 new_return(38);
14293
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.msg_more_x,f))
14294 new_return(39);
14295
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.msg_more_y,f))
14296 new_return(40);
14297
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.msg_more_is_offset,f))
14298 new_return(41);
14299
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.msg_speed,f))
14300 new_return(42);
14301
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(zinit.gravity,f))
14302 new_return(43);
14303
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(zinit.swimgravity,f))
14304 new_return(44);
14305
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(zinit.terminalv,f))
14306 new_return(45);
14307
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.hero_swim_speed,f))
14308 new_return(46);
14309
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.hero_swim_mult,f))
14310 new_return(47);
14311
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.hero_swim_div,f))
14312 new_return(48);
14313
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(zinit.heroSideswimUpStep,f))
14314 new_return(49);
14315
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(zinit.heroSideswimSideStep,f))
14316 new_return(50);
14317
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(zinit.heroSideswimDownStep,f))
14318 new_return(51);
14319
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(zinit.exitWaterJump,f))
14320 new_return(52);
14321
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(zinit.heroStep,f))
14322 new_return(53);
14323
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.heroAnimationStyle,f))
14324 new_return(54);
14325
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.jump_hero_layer_threshold,f))
14326 new_return(55);
14327
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(zinit.bunny_ltm,f))
14328 new_return(56);
14329
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(zinit.start_dmap,f))
14330 new_return(57);
14331
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(zinit.subscrSpeed,f))
14332 new_return(58);
14333
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.switchhookstyle,f))
14334 new_return(59);
14335
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.magicdrainrate,f))
14336 new_return(60);
14337
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputzf(zinit.shove_offset,f))
14338 new_return(61);
14339
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putbitstr(zinit.gen_doscript, f))
14340 new_return(62);
14341
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putbmap(zinit.gen_exitState, f))
14342 new_return(63);
14343
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putbmap(zinit.gen_reloadState, f))
14344 new_return(64);
14345
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putbmap(zinit.gen_initd, f))
14346 new_return(65);
14347
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putbmap(zinit.gen_eventstate, f))
14348 new_return(66);
14349
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putbmap(zinit.gen_data, f))
14350 new_return(67);
14351
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putbmap(zinit.screen_data, f))
14352 new_return(68);
14353
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (!p_putc(zinit.spriteflickerspeed, f))
14354 new_return(69);
14355
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (!p_putc(zinit.spriteflickercolor, f))
14356 new_return(70);
14357
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (!p_putc(zinit.spriteflickertransp, f))
14358 new_return(71);
14359
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (!p_iputzf(zinit.air_drag, f))
14360 new_return(72);
14361
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (!p_iputw(zinit.light_wave_rate, f))
14362 new_return(73);
14363
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (!p_iputw(zinit.light_wave_size, f))
14364 new_return(74);
14365
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (!p_putc(zinit.region_mapping, f))
14366 new_return(75);
14367
2/2
✓ Branch 0 taken 4608 times.
✓ Branch 1 taken 18 times.
4626 for(uint q = 0; q < NUM_BOTTLE_SLOTS; ++q)
14368
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if (!p_putc(zinit.bottle_slot[q], f))
14369 new_return(76);
14370
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (!p_putbvec(zinit.lvlswitches, f))
14371 new_return(77);
14372
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (!p_iputw(zinit.item_spawn_flicker, f))
14373 new_return(78);
14374
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (!p_iputw(zinit.item_timeout_dur, f))
14375 new_return(79);
14376
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (!p_iputw(zinit.item_timeout_flicker, f))
14377 new_return(80);
14378
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (!p_putc(zinit.item_flicker_speed, f))
14379 new_return(81);
14380
2/2
✓ Branch 0 taken 90 times.
✓ Branch 1 taken 18 times.
108 for(int q = 0; q < SPRITE_THRESHOLD_MAX; ++q)
14381
1/2
✓ Branch 0 taken 90 times.
✗ Branch 1 not taken.
90 if (!p_iputw(zinit.sprite_z_thresholds[q], f))
14382 new_return(82);
14383
14384
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
14385 {
14386 9 section_size=writesize;
14387 9 }
14388 18 }
14389
14390
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
14391 {
14392 char ebuf[80];
14393 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
14394 jwin_alert("Error: writeinitdata()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
14395 }
14396
14397 9 new_return(0);
14398 }
14399
14400 9 int32_t writeitemdropsets(PACKFILE *f, zquestheader *Header)
14401 {
14402 //these are here to bypass compiler warnings about unused arguments
14403 9 Header=Header;
14404
14405 9 dword section_id=ID_ITEMDROPSETS;
14406 9 dword section_version=V_ITEMDROPSETS;
14407 // dword section_size=0;
14408 9 dword section_size = 0;
14409 9 word num_item_drop_sets=count_item_drop_sets();
14410
14411 //section id
14412
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
14413 {
14414 new_return(1);
14415 }
14416
14417 //section version info
14418
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
14419 {
14420 new_return(2);
14421 }
14422
14423
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
14424 {
14425 new_return(3);
14426 }
14427
14428
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 18 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
14429 {
14430 18 fake_pack_writing=(writecycle==0);
14431
14432 //section size
14433
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
14434 {
14435 new_return(4);
14436 }
14437
14438 18 writesize=0;
14439
14440 //finally... section data
14441
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(num_item_drop_sets,f))
14442 {
14443 new_return(5);
14444 }
14445
14446
2/2
✓ Branch 0 taken 236 times.
✓ Branch 1 taken 18 times.
254 for(int32_t i=0; i<num_item_drop_sets; i++)
14447 {
14448
1/2
✓ Branch 0 taken 236 times.
✗ Branch 1 not taken.
236 if(!pfwrite(item_drop_sets[i].name, sizeof(item_drop_sets[i].name)-1, f))
14449 {
14450 new_return(6);
14451 }
14452
14453
2/2
✓ Branch 0 taken 2360 times.
✓ Branch 1 taken 236 times.
2596 for(int32_t j=0; j<10; ++j)
14454 {
14455
1/2
✓ Branch 0 taken 2360 times.
✗ Branch 1 not taken.
2360 if(!p_iputw(item_drop_sets[i].item[j],f))
14456 {
14457 new_return(7);
14458 }
14459 2360 }
14460
14461
2/2
✓ Branch 0 taken 2596 times.
✓ Branch 1 taken 236 times.
2832 for(int32_t j=0; j<11; ++j)
14462 {
14463
1/2
✓ Branch 0 taken 2596 times.
✗ Branch 1 not taken.
2596 if(!p_iputw(item_drop_sets[i].chance[j],f))
14464 {
14465 new_return(8);
14466 }
14467 2596 }
14468 236 }
14469
14470
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
14471 {
14472 9 section_size=writesize;
14473 9 }
14474 18 }
14475
14476
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
14477 {
14478 char ebuf[80];
14479 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
14480 jwin_alert("Error: writeitemdropsets()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
14481 }
14482
14483 9 new_return(0);
14484 }
14485
14486 9 int32_t writefavorites(PACKFILE *f, zquestheader*)
14487 {
14488 9 dword section_id=ID_FAVORITES;
14489 9 dword section_version=V_FAVORITES;
14490 9 dword section_size = 0;
14491
14492 //section id
14493
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
14494 {
14495 new_return(1);
14496 }
14497
14498 //section version info
14499
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
14500 {
14501 new_return(2);
14502 }
14503
14504
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
14505 {
14506 new_return(3);
14507 }
14508
14509
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 18 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
14510 {
14511 18 fake_pack_writing=(writecycle==0);
14512
14513 //section size
14514
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
14515 new_return(4);
14516
14517 18 writesize=0;
14518
14519
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(FAVORITECOMBO_PER_ROW,f))
14520 new_return(16);
14521
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(FAVORITECOMBO_PER_PAGE,f)) // Just in case pages get resized again
14522 new_return(17);
14523
14524 18 word favcmb_cnt = 0;
14525
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 22234 times.
22238 for(int q = MAXFAVORITECOMBOS-1; q >= 0; --q)
14526
2/2
✓ Branch 0 taken 22220 times.
✓ Branch 1 taken 14 times.
22234 if(favorite_combos[q] != -1)
14527 {
14528 14 favcmb_cnt = q+1;
14529 14 break;
14530 }
14531
14532
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(favcmb_cnt,f)) // This'll probably never change, huh?
14533 new_return(5);
14534
14535
2/2
✓ Branch 0 taken 460 times.
✓ Branch 1 taken 18 times.
478 for(int i=0; i<favcmb_cnt; ++i)
14536 {
14537
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if (!p_putc(favorite_combo_modes[i], f))
14538 new_return(6);
14539
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if (!p_iputl(favorite_combos[i], f))
14540 new_return(7);
14541 460 }
14542
14543
14544 18 word max_combo_cols = MAX_COMBO_COLS;
14545
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(max_combo_cols,f))
14546 new_return(9);
14547
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int q = 0; q < max_combo_cols; ++q)
14548 {
14549
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(First[q],f))
14550 new_return(10);
14551
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(combo_alistpos[q],f))
14552 new_return(11);
14553
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(combo_pool_listpos[q],f))
14554 new_return(12);
14555 72 }
14556 18 word max_mappages = MAX_MAPPAGE_BTNS;
14557
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(max_mappages,f))
14558 new_return(13);
14559
2/2
✓ Branch 0 taken 162 times.
✓ Branch 1 taken 18 times.
180 for(int q = 0; q < max_mappages; ++q)
14560 {
14561
1/2
✓ Branch 0 taken 162 times.
✗ Branch 1 not taken.
162 if(!p_iputl(map_page[q].map,f))
14562 new_return(14);
14563
1/2
✓ Branch 0 taken 162 times.
✗ Branch 1 not taken.
162 if(!p_iputl(map_page[q].screen,f))
14564 new_return(15);
14565 162 }
14566
14567
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
14568 {
14569 9 section_size=writesize;
14570 9 }
14571 18 }
14572
14573
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
14574 {
14575 char ebuf[80];
14576 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
14577 jwin_alert("Error: writefavorites()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
14578 }
14579
14580 9 new_return(0);
14581 }
14582
14583 9 static int32_t _save_unencoded_quest_int(const char *filename, bool compressed, const char *afname)
14584 {
14585
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!afname) afname = filename;
14586 9 reset_combo_animations();
14587 9 reset_combo_animations2();
14588 9 strcpy(header.id_str,QH_NEWIDSTR);
14589 9 header.zelda_version = ZELDA_VERSION;
14590 9 header.internal = INTERNAL_VERSION;
14591 9 header.data_flags[ZQ_TILES] = true;
14592 9 header.data_flags[ZQ_CHEATS2] = 1;
14593 9 header.build=VERSION_BUILD;
14594
14595
2/2
✓ Branch 0 taken 2268 times.
✓ Branch 1 taken 9 times.
2277 for(int32_t i=0; i<MAXCUSTOMMIDIS; i++)
14596 {
14597 2268 set_bit(midi_flags,i,int32_t(customtunes[i].data!=NULL));
14598 2268 }
14599
14600 char zinfofilename[2048];
14601 9 replace_extension(zinfofilename, afname, "zinfo", 2047);
14602
14603 9 box_start(1, "Saving Quest", get_zc_font(font_lfont), font, true);
14604 9 box_out("Saving Quest...");
14605 9 box_eol();
14606 9 box_eol();
14607
14608
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 std::string tmp_filename = util::create_temp_file_path(filename);
14609
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 PACKFILE *f = pack_fopen_password(tmp_filename.c_str(),compressed?F_WRITE_PACKED:F_WRITE, "");
14610
14611
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!f)
14612 return 1;
14613
14614
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Header...");
14615
14616
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9 times.
9 if(writeheader(f,&header)!=0)
14617 return 2;
14618
14619
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14620
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14621
14622
14623
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(header.external_zinfo)
14624 {
14625 PACKFILE *inf = pack_fopen_password(zinfofilename, F_WRITE, "");
14626
14627 box_out("Writing ZInfo...");
14628 if(inf)
14629 {
14630 if(writezinfo(inf,ZI)!=0)
14631 return 2;
14632
14633 pack_fclose(inf);
14634 box_out("okay.");
14635 }
14636 else box_out(" ...file failure");
14637 box_eol();
14638 }
14639 else
14640 {
14641
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing ZInfo...");
14642
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writezinfo(f,ZI)!=0)
14643 return 2;
14644
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14645
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14646 }
14647
14648
14649
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Rules...");
14650
14651
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writerules(f,&header)!=0)
14652 return 3;
14653
14654
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14655
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14656
14657
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Strings...");
14658
14659
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writestrings(f, ZELDA_VERSION, VERSION_BUILD, 0, MAXMSGS)!=0)
14660 return 4;
14661
14662
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14663
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14664
14665
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Doors...");
14666
14667
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writedoorcombosets(f,&header)!=0)
14668 return 5;
14669
14670
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14671
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14672
14673
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing DMaps...");
14674
14675
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writedmaps(f,header.zelda_version,header.build,0,MAXDMAPS)!=0)
14676 return 6;
14677
14678
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14679
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14680
14681
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing &QMisc. Data...");
14682
14683
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writemisc(f,&header)!=0)
14684 return 7;
14685
14686
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14687
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14688
14689
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing &QMisc. Colors...");
14690
14691
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9 times.
9 if(writemisccolors(f,&header)!=0)
14692 return 8;
14693
14694
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14695
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14696
14697
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Game Icons...");
14698
14699
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writegameicons(f,&header)!=0)
14700 return 9;
14701
14702
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14703
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14704
14705
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Items...");
14706
14707
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writeitems(f,&header)!=0)
14708 return 10;
14709
14710
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14711
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14712
14713
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Weapons...");
14714
14715
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9 times.
9 if(writeweapons(f,&header)!=0)
14716 return 11;
14717
14718
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14719
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14720
14721
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Maps...");
14722
14723
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writemaps(f,&header)!=0)
14724 return 12;
14725
14726
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14727
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14728
14729
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Combos...");
14730
14731
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9 times.
9 if(writecombos(f,header.zelda_version,header.build,0,MAXCOMBOS)!=0)
14732 return 13;
14733
14734
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14735
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14736
14737
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Combo Aliases...");
14738
14739
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writecomboaliases(f,header.zelda_version,header.build)!=0)
14740 return 14;
14741
14742
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14743
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14744
14745
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Color Data...");
14746
14747
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writecolordata(f,header.zelda_version,header.build,0,newerpdTOTAL)!=0)
14748 return 15;
14749
14750
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14751
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14752
14753
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Tiles...");
14754
14755
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writetiles(f,header.zelda_version,header.build,0,NEWMAXTILES)!=0)
14756 return 16;
14757
14758
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14759
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14760
14761
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing MIDIs...");
14762
14763
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9 times.
9 if(writemidis(f)!=0)
14764 return 17;
14765
14766
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14767
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14768
14769
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Cheat Codes...");
14770
14771
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9 times.
9 if(writecheats(f,&header)!=0)
14772 return 18;
14773
14774
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14775
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14776
14777
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Init. Data...");
14778
14779
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writeinitdata(f,&header)!=0)
14780 return 19;
14781
14782
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14783
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14784
14785
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Custom Guy Data...");
14786
14787
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writeguys(f,&header)!=0)
14788 return 20;
14789
14790
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14791
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14792
14793
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Custom Hero Sprite Data...");
14794
14795
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writeherosprites(f,&header)!=0)
14796 return 21;
14797
14798
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14799
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14800
14801
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Custom Subscreen Data...");
14802
14803
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writesubscreens(f,&header)!=0)
14804 return 22;
14805
14806
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14807
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14808
14809
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing FF Script Data...");
14810
14811
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writeffscript(f,&header)!=0)
14812 return 23;
14813
14814
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14815
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14816
14817
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing SFX Data...");
14818
14819
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writesfx(f,&header)!=0)
14820 return 24;
14821
14822
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14823
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14824
14825
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Item Drop Sets...");
14826
14827
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9 times.
9 if(writeitemdropsets(f, &header)!=0)
14828 return 25;
14829
14830
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14831
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14832
14833
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Favorite Combos...");
14834
14835
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writefavorites(f, &header)!=0)
14836 return 26;
14837
14838
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14839
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14840
14841
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 pack_fclose(f);
14842
14843
14844
3/4
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 3 times.
9 if(header.use_keyfile&&header.dirty_password)
14845 {
14846 char const* kfname = filename;
14847 char keyfilename[2048]={0};
14848 zprint2("Writing key files for '%s'\n", kfname);
14849
14850 char temp_pw[QSTPWD_LEN] = {0};
14851 uint ind = 0;
14852 for(char const* ext : {"key","zpwd","zcheat"})
14853 {
14854 replace_extension(keyfilename, kfname, ext, 2047);
14855 PACKFILE *fp = pack_fopen_password(keyfilename, F_WRITE, "");
14856 char msg[80] = {0};
14857 sprintf(msg, "ZQuest Auto-Generated Quest Password Key File. DO NOT EDIT!");
14858 msg[78]=13;
14859 msg[79]=10;
14860 pfwrite(msg, 80, fp);
14861 p_iputw(header.zelda_version,fp);
14862 p_putc(header.build,fp);
14863 char const* pwd = header.password;
14864 if(ind == 2) //.zcheat, hashed pwd
14865 {
14866 char hashmap = 'Z';
14867 hashmap += 'Q';
14868 hashmap += 'U';
14869 hashmap += 'E';
14870 hashmap += 'S';
14871 hashmap += 'T';
14872 for ( int q = 0; q < QSTPWD_LEN; ++q )
14873 {
14874 temp_pw[q] = header.password[q];
14875 temp_pw[q] += hashmap;
14876 }
14877 pwd = temp_pw;
14878 }
14879 pfwrite(pwd, strlen(pwd), fp);
14880 pack_fclose(fp);
14881 ++ind;
14882 }
14883 }
14884
14885 // Move file to destination at end, to avoid issues with file being unavailable to test mode.
14886 9 std::error_code ec;
14887
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 fs::rename(tmp_filename, filename, ec);
14888
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if (ec)
14889 {
14890 al_trace("Error saving: %s\n", std::strerror(ec.value()));
14891 return ec.value();
14892 }
14893
14894
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 strncpy(header.zelda_version_string, getVersionString(), sizeof(header.zelda_version_string));
14895
14896 #ifdef __EMSCRIPTEN__
14897 em_sync_fs();
14898 #endif
14899
14900 9 return 0;
14901 9 }
14902
14903 // #ifdef _WIN32
14904 // static std::time_t to_time_t(FILETIME const& ft) {
14905 // uint64_t t = (static_cast<uint64_t>(ft.dwHighDateTime) << 32) | ft.dwLowDateTime;
14906 // t -= 116444736000000000ull;
14907 // t /= 10000000u;
14908 // return static_cast<std::time_t>(t);
14909 // }
14910 // #else
14911 // #endif
14912 template<typename TP>
14913 6 static std::time_t to_time_t(TP tp) {
14914 using namespace std::chrono;
14915 6 auto sctp = time_point_cast<system_clock::duration>(tp - TP::clock::now() + system_clock::now());
14916 6 return system_clock::to_time_t(sctp);
14917 }
14918
14919 6 std::string get_time_last_modified_string(std::string path)
14920 {
14921
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 auto write_time = fs::last_write_time(path);
14922 // TODO: C++20 but not supported yet.
14923 // auto tt = std::chrono::clock_cast<std::chrono::system_clock>(write_time);
14924 6 std::time_t tt = to_time_t(write_time);
14925 6 std::tm *gmt = std::gmtime(&tt);
14926 6 std::stringstream buffer;
14927
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 buffer << std::put_time(gmt, "%Y-%m-%d");
14928
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 std::string formattedFileTime = buffer.str();
14929 6 return formattedFileTime;
14930
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 }
14931
14932 9 int32_t save_unencoded_quest(const char *filename, bool compressed, const char *afname)
14933 {
14934 // Always backup quest if it was last saved in a different version of the editor,
14935 // or if this a new file and is overwritting another qst file.
14936
10/16
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 6 times.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 3 times.
✓ Branch 7 taken 6 times.
✓ Branch 8 taken 3 times.
✓ Branch 9 taken 6 times.
✓ Branch 10 taken 3 times.
✓ Branch 11 taken 6 times.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
9 if (exists(filename) && std::string(getVersionString()) != header.zelda_version_string)
14937 {
14938 6 std::string backup_name;
14939
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 std::string last_mod = get_time_last_modified_string(filename);
14940
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if (strlen(header.zelda_version_string) > 0)
14941 {
14942
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 backup_name = fmt::format("{}-v{}", last_mod, header.zelda_version_string);
14943 6 }
14944 else
14945 {
14946 backup_name = fmt::format("{}", last_mod);
14947 }
14948
7/14
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 6 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 6 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 6 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 6 times.
✗ Branch 13 not taken.
6 std::string backup_fname = fmt::format("{}-{}{}", fs::path(filename).stem().string(), backup_name, fs::path(filename).extension().string());
14949
3/6
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
6 fs::path backup_path = fs::path("backups") / backup_fname;
14950
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if (!fs::exists(backup_path))
14951 {
14952
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 fs::create_directories(fs::path("backups"));
14953
3/6
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
6 if (fs::copy_file(filename, backup_path))
14954 {
14955
5/10
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 6 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✓ Branch 9 taken 6 times.
6 InfoDialog("Quest Backup", fmt::format("A backup has been saved to {}", backup_path.string())).show();
14956 6 }
14957 else
14958 {
14959 InfoDialog("Quest Backup", fmt::format("Failed to save backup at {}", backup_path.string())).show();
14960 }
14961 6 }
14962 6 }
14963
14964 9 auto ret = _save_unencoded_quest_int(filename,compressed,afname);
14965 9 fake_pack_writing = false;
14966
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(ret)
14967 {
14968 box_out("-- Error saving quest file! --");
14969 box_end(true);
14970 }
14971 9 else box_end(false);
14972 9 return ret;
14973 }
14974
14975 9 int32_t save_quest(const char *filename, bool timed_save)
14976 {
14977
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 int32_t retention=timed_save?AutoSaveRetention:AutoBackupRetention;
14978
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 bool compress=!(timed_save&&UncompressedAutoSaves);
14979 char ext1[5];
14980 9 ext1[0]=0;
14981
14982
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(timed_save)
14983 {
14984 sprintf(ext1, "qt");
14985 }
14986 else
14987 {
14988 9 sprintf(ext1, "qb");
14989 }
14990
14991
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(retention)
14992 {
14993 char backupname[2048];
14994 char backupname2[2048];
14995 char ext[12];
14996
14997 for(int32_t i=retention-1; i>0; --i)
14998 {
14999 sprintf(ext, "%s%d", ext1, i-1);
15000 replace_extension(backupname, filepath, ext, 2047);
15001
15002 if(exists(backupname))
15003 {
15004 sprintf(ext, "%s%d", ext1, i);
15005 replace_extension(backupname2, filepath, ext, 2047);
15006
15007 if(exists(backupname2))
15008 {
15009 remove(backupname2);
15010 }
15011
15012 rename(backupname, backupname2);
15013 }
15014 }
15015
15016 //don't do this if we're not saving to the same name -DD
15017 if(!timed_save && !strcmp(filepath, filename))
15018 {
15019 sprintf(ext, "%s%d", ext1, 0);
15020 replace_extension(backupname, filepath, ext, 2047);
15021 rename(filepath, backupname);
15022 }
15023 }
15024
15025 int32_t ret;
15026 9 ret = save_unencoded_quest(filename, compress, filename);
15027
15028 9 return ret;
15029 }
15030
15031 1 void center_zq_class_dialogs()
15032 {
15033 1 jwin_center_dialog(pwd_dlg);
15034 1 }
15035
15036 void zmap::prv_secrets(bool high16only)
15037 {
15038 mapscr *s = &prvscr;
15039 mapscr *t = prvlayers;
15040 int32_t ft=0;
15041
15042 for(int32_t i=0; i<176; i++)
15043 {
15044 if(!high16only)
15045 {
15046 for(int32_t j=-1; j<6; j++)
15047 {
15048 int32_t newflag = -1;
15049
15050 for(int32_t iter=0; iter<2; ++iter)
15051 {
15052 if(!t[j].valid)
15053 continue;
15054
15055 int32_t checkflag=combobuf[t[j].data[i]].flag;
15056
15057 if(iter==1)
15058 {
15059 checkflag=t[j].sflag[i];
15060 }
15061
15062 ft = combo_trigger_flag_to_secret_combo_index(checkflag);
15063 if (ft != -1)
15064 {
15065 if(j==-1)
15066 {
15067 s->data[i] = s->secretcombo[ft];
15068 s->cset[i] = s->secretcset[ft];
15069 newflag = s->secretflag[ft];
15070 }
15071 else
15072 {
15073 t[j].data[i] = t[j].secretcombo[ft];
15074 t[j].cset[i] = t[j].secretcset[ft];
15075 newflag = t[j].secretflag[ft];
15076 }
15077 }
15078 }
15079
15080 if(newflag >-1)
15081 {
15082 ((j==-1) ? s->sflag[i] : t[j].sflag[i]) = newflag;
15083 }
15084 }
15085 }
15086
15087 //if(true)
15088 //{
15089 int32_t newflag = -1;
15090
15091 for(int32_t iter=0; iter<2; ++iter)
15092 {
15093 int32_t checkflag=combobuf[s->data[i]].flag;
15094
15095 if(iter==1)
15096 {
15097 checkflag=s->sflag[i];
15098 }
15099
15100 if((checkflag > 15)&&(checkflag < 32))
15101 {
15102 s->data[i] = s->secretcombo[(checkflag)-16+4];
15103 s->cset[i] = s->secretcset[(checkflag)-16+4];
15104 newflag = s->secretflag[(checkflag)-16+4];
15105 // putit = true;
15106 }
15107 }
15108
15109 if(newflag >-1) s->sflag[i] = newflag;
15110
15111 for(int32_t j=0; j<6; j++)
15112 {
15113 if(!t[j].valid) continue;
15114
15115 int32_t newflag2 = -1;
15116
15117 for(int32_t iter=0; iter<2; ++iter)
15118 {
15119 int32_t checkflag=combobuf[t[j].data[i]].flag;
15120
15121 if(iter==1)
15122 {
15123 checkflag=t[j].sflag[i];
15124 }
15125
15126 if((checkflag > 15)&&(checkflag < 32))
15127 {
15128 t[j].data[i] = t[j].secretcombo[(checkflag)-16+4];
15129 t[j].cset[i] = t[j].secretcset[(checkflag)-16+4];
15130 newflag2 = t[j].secretflag[(checkflag)-16+4];
15131 }
15132 }
15133
15134 if(newflag2 >-1) t[j].sflag[i] = newflag2;
15135 }
15136 }
15137
15138 //FFCs
15139 word num_ffcs = s->numFFC();
15140 for(word i=0; i<num_ffcs; ++i)
15141 {
15142 if(!high16only)
15143 {
15144 for(int32_t iter=0; iter<1; ++iter)
15145 {
15146 int32_t checkflag=combobuf[s->ffcs[i].data].flag;
15147
15148 if(iter==1)
15149 {
15150 checkflag=s->sflag[i];
15151 }
15152
15153 ft = combo_trigger_flag_to_secret_combo_index(checkflag);
15154 if (ft != -1)
15155 {
15156 s->ffcs[i].data = s->secretcombo[ft];
15157 s->ffcs[i].cset = s->secretcset[ft];
15158 }
15159 }
15160 }
15161
15162 if(!(s->flags2&fCLEARSECRET) || high16only || s->flags4&fENEMYSCRTPERM)
15163 {
15164 for(int32_t iter=0; iter<1; ++iter)
15165 {
15166 int32_t checkflag=combobuf[s->ffcs[i].data].flag;
15167
15168 if(iter==1)
15169 {
15170 // FFCs can't have flags! Yet...
15171 }
15172
15173 if((checkflag > 15)&&(checkflag < 32))
15174 {
15175 s->ffcs[i].data = s->secretcombo[checkflag - 16 + 4];
15176 s->ffcs[i].cset = s->secretcset[checkflag-16+4];
15177 }
15178 }
15179 }
15180 }
15181 }
15182